Table and paintable canvas Object refresh

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.

Use the 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.

1 Like

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

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.

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.

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.

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.

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.

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.

1 Like

You need to repaint. the table, as well.

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.

1 Like

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

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(), and assign its return value back to the data property of the table. Like so:

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

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.

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.