# Table and paintable canvas Object refresh

**URL:** <https://forum.inductiveautomation.com/t/table-and-paintable-canvas-object-refresh/16412>\
**Category:** Ignition\
**Created:** [December 24, 2017, 6:02am UTC](https://forum.inductiveautomation.com/t/table-and-paintable-canvas-object-refresh/16412 "2017-12-24T06:02:08Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![mgraham](https://avatars.discourse-cdn.com/v4/letter/m/9fc348/32.png) [@mgraham](https://forum.inductiveautomation.com/u/mgraham)\
**Post date:** [December 24, 2017, 6:02am UTC](https://forum.inductiveautomation.com/t/table-and-paintable-canvas-object-refresh/16412/1 "2017-12-24T06:02:09Z")

</div>

I have a simple question.  
I use things like tables and the paintable canvas, and find i have to use a kludge to get them to refresh when I want them to. Is it possible to add a refresh method? I dislike using kludges because they may not work in future versions.

thanks.

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [December 24, 2017, 2:12pm UTC](https://forum.inductiveautomation.com/t/table-and-paintable-canvas-object-refresh/16412/2 "2017-12-24T14:12:44Z")

</div>

Use the [system.db.refresh()](https://docs.inductiveautomation.com/display/DOC79/system.db.refresh) function. That’s the documented and supported method to refresh things on demand. (As opposed to a polling binding, etc.) Although it was created to refresh dataset bindings, it actually refreshes any binding.

---

<div class="post-metadata">

**Author:** ![mgraham](https://avatars.discourse-cdn.com/v4/letter/m/9fc348/32.png) [@mgraham](https://forum.inductiveautomation.com/u/mgraham)\
**Post date:** [December 24, 2017, 9:52pm UTC](https://forum.inductiveautomation.com/t/table-and-paintable-canvas-object-refresh/16412/3 "2017-12-24T21:52:34Z")

</div>

Thanks. I’ll try it, I assumed the dataset had to come from a database for that function.

---

<div class="post-metadata">

**Author:** ![mgraham](https://avatars.discourse-cdn.com/v4/letter/m/9fc348/32.png) [@mgraham](https://forum.inductiveautomation.com/u/mgraham)\
**Post date:** [December 24, 2017, 10:09pm UTC](https://forum.inductiveautomation.com/t/table-and-paintable-canvas-object-refresh/16412/4 "2017-12-24T22:09:43Z")

</div>

It didn’t work. here is the message:

WARN [PMITable-AWT-EventQueue-0] system.db.refresh() was unable to find a refresh-compatible property binding on Table.data

The table dataset is initally fed from a csv file and there is no binding.  
What I do now, is:

svr=event.source.parent.getComponent(‘Table’).selectedRow   
event.source.parent.getComponent(‘Table’).selectedRow = 0  
event.source.parent.getComponent(‘Table’).selectedRow = 1  
event.source.parent.getComponent(‘Table’).selectedRow = svr

which works regardless of which row is currently selected.

for the paintable canvas, I have a custom property I drive a value to.

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [December 26, 2017, 6:49pm UTC](https://forum.inductiveautomation.com/t/table-and-paintable-canvas-object-refresh/16412/5 "2017-12-26T18:49:12Z")

</div>

I guess I don’t understand what you are trying to refresh on the table. I presumed the table data was coming from a binding. Since it’s static, I don’t see what there is to refresh.

---

<div class="post-metadata">

**Author:** ![albetro.15](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/albetro.15/32/3922_2.png) [@albetro.15](https://forum.inductiveautomation.com/u/albetro.15)\
**Post date:** [January 3, 2018, 8:42am UTC](https://forum.inductiveautomation.com/t/table-and-paintable-canvas-object-refresh/16412/6 "2018-01-03T08:42:00Z")

</div>

I think I see the problem. Lets say that for a chart (not easy chart) we have binded a button to the tooltips property. If the property is set to True when the client/chart is shown, then the chart will always have the tooltip active even if we deactivated it with the button. A refresh of the chart/table would be needed to update these kind of properties. Is this the problem you have ? I currently having a similar issue, if I find the soluction Ill let you know.

---

<div class="post-metadata">

**Author:** ![mgraham](https://avatars.discourse-cdn.com/v4/letter/m/9fc348/32.png) [@mgraham](https://forum.inductiveautomation.com/u/mgraham)\
**Post date:** [January 4, 2018, 3:21pm UTC](https://forum.inductiveautomation.com/t/table-and-paintable-canvas-object-refresh/16412/7 "2018-01-04T15:21:04Z")

</div>

Pretty simple to explain:  
updating a table with tabledata.setValueAt(row,column,value) sets the value, but you don’t see it until something else causes the table to refresh.

---

<div class="post-metadata">

**Author:** ![mgraham](https://avatars.discourse-cdn.com/v4/letter/m/9fc348/32.png) [@mgraham](https://forum.inductiveautomation.com/u/mgraham)\
**Post date:** [January 4, 2018, 3:24pm UTC](https://forum.inductiveautomation.com/t/table-and-paintable-canvas-object-refresh/16412/8 "2018-01-04T15:24:15Z")

</div>

Also, for the paintable canvas, if you draw on it you have to change a bound item to get it to refresh and show the drawing.

---

<div class="post-metadata">

**Author:** ![mrogers](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/mrogers/32/4110_2.png) [@mrogers](https://forum.inductiveautomation.com/u/mrogers)\
**Post date:** [January 4, 2018, 4:13pm UTC](https://forum.inductiveautomation.com/t/table-and-paintable-canvas-object-refresh/16412/9 "2018-01-04T16:13:08Z")

</div>

For the table update, I don’t recognize the function you mentioned - do you mean “system.dataset.setValue(dataset, rowIndex, columnName, value)”?

For the paintable canvas - just call its repaint method any time. So if you were to do it from any extension function, just use event.source.repaint(). You don’t need to pass it any sort of event, it’ll take care of that.

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [January 4, 2018, 4:21pm UTC](https://forum.inductiveautomation.com/t/table-and-paintable-canvas-object-refresh/16412/10 "2018-01-04T16:21:36Z")

</div>

> [@mgraham](#):
>
> updating a table with tabledata.setValueAt(row,column,value) sets the value, but you don't see it until something else causes the table to refresh.

You need to repaint. the table, as well.

```auto
table = event.source.parent.getComponent('Table')

table.data.setValueAt(row,column,value)

table.repaint()

```

EDIT: I was writing as Phil's post below came in, but it stands that best practice is to use system.dataset.setValue() to create a new dataset with the updated value, then write it back to the table.

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [January 4, 2018, 4:23pm UTC](https://forum.inductiveautomation.com/t/table-and-paintable-canvas-object-refresh/16412/11 "2018-01-04T16:23:23Z")

</div>

setValueAt() is a method built into the dataset itself.

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [January 4, 2018, 4:24pm UTC](https://forum.inductiveautomation.com/t/table-and-paintable-canvas-object-refresh/16412/12 "2018-01-04T16:24:40Z")

</div>

> [@mgraham](#):
>
> Pretty simple to explain:updating a table with tabledata.setValueAt(row,column,value) sets the value, but you don't see it until something else causes the table to refresh.

There's your problem. You are modifying a dataset in place. That won't generate a property change event, and therefore won't cause any update. That method is not part of the Dataset interface, and is actually intended only for construction of a dataset prior to assignment anywhere. For your code to work properly going forward, you need to use [system.dataset.setValue()](https://docs.inductiveautomation.com/display/DOC79/system.dataset.setValue), and assign its return value back to the data property of the table. Like so:

```auto
table = event.source
# compute/obtain row, col, newvalue .....
table.data = system.dataset.setValue(table.data, row, col, newvalue)

```

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [January 4, 2018, 4:31pm UTC](https://forum.inductiveautomation.com/t/table-and-paintable-canvas-object-refresh/16412/13 "2018-01-04T16:31:50Z")

</div>

> [@mgraham](#):
>
> Also, for the paintable canvas, if you draw on it you have to change a bound item to get it to refresh and show the drawing.

Just add a custom property to the paintable canvas, unbound, and change it via scripting whenever you want to redraw. Could be as simple as a boolean that you toggle.

---

<div class="post-metadata">

**Author:** ![mgraham](https://avatars.discourse-cdn.com/v4/letter/m/9fc348/32.png) [@mgraham](https://forum.inductiveautomation.com/u/mgraham)\
**Post date:** [January 5, 2018, 5:18am UTC](https://forum.inductiveautomation.com/t/table-and-paintable-canvas-object-refresh/16412/14 "2018-01-05T05:18:30Z")

</div>

Thank you all. Both methods worked for me.  
As recommended I’ll use  
system.dataset.setValue(table.data, row, col, newvalue)

as for the paintable canvas, that is what I’ve been doing, I just thought it felt like a work around, but I’ll just be happy it works.
