Power Table Update Query to SQLSvrExpress

OK - a bit new to Ignition.
I have a Power Table with the Data bound to a Database Table in SQLSvrExpress.
Works fine and shows the data.
I’ve tried to make this data editable, by setting the editable property for the column, and configuring the onCellEdited function as per the Manual. After editing the data in the table, the data goes immediately back to the original value.
What am I missing?

onCellEdited Function

id = self.data.getValueAt(rowIndex, ‘pkid’) #Get the id of the database column.
query = “UPDATE DeviceCodes SET %s = ? WHERE pkid = ?” % (colName)
args = [newValue, id]
system.db.runPrepUpdate(query, args)
system.db.refresh(self,“data”)

1 Like

You can force a write to a dataset by setting the value like this (instead of your refresh).

self.data = system.dataset.setValue(self.data, rowIndex, colIndex, newValue)

Though that could hide issues with the query failing to update the original data. So perhaps it’s worth to try to keep your current way of doing it. You could try to use system.util.invokeLater.

With the invokeLater, it should first execute the query, then release focus on the cell, and only after rendering update the data.

Do any errors show in the console?
More than likely your table is in a database that is not the default database and you aren’t specifying the database connection on your runPrepUpdate call.

Thanks for advice. i eventually found the script was missing a couple of lines which were commented out in the template script and it works OK.