Editable checkboxes in Power Table

Hello, I have a customer who needs to select rows in a table for editing purposes. The table data is bound to SQL and polling is relative to the project. My issue is that they want checkboxes instead of the built in row selection look. I can make editable checkboxes but without writing back to SQL the checked boxes become unchecked when the data refreshes. I tried making a separate table just for the checkboxes and binding the look (checked vs unchecked) to the selected rows but problem here is the selected rows property is read only (selected row is editable but I need option to select more than one row). So if I can find a way to edit selected rowS I can make this work or I’m hoping someone else has a creative workaround.

I need a table that looks like the following, has the ability to check rows and determine which rows are checked. Data updates regularly from SQL and columns are sortable.

Thanks!

I would move the original SQL binding (without the checkbox column) to a custom property, possibly on the root container. Then bind the table’s data to an objectScript() expression that will add the desired checkboxes to the dataset. The objectScript() function can access the previous data to obtain the current checkboxes to apply to the new data. Put the following in a project script:[code]from java.lang import Boolean
from com.inductiveautomation.ignition.common.util import DatasetBuilder

def addSelectColumn(binding, idColumn, newData):
component = binding.target
prevData = getattr(component, binding.targetPropertyName)
idMap = {}
try:
idIndex = prevData.getColumnIndex(idColumn)
for r in range(prevData.rowCount):
if prevData.getValueAt(r, 0):
idMap[prevData.getValueAt(r, idIndex)] = True
except:
# If any problems are encountered building the index (and
# there will be on first execution), assume nothing is checked.
pass
builder = DatasetBuilder.newBuilder()
builder.colNames([‘Select’]+list(newData.columnNames))
builder.colTypes([Boolean]+list(newData.columnTypes))
idIndex = newData.getColumnIndex(idColumn)
crange = range(newData.columnCount)
for r in range(newData.rowCount):
selected = idMap.get(newData.getValueAt(r, idIndex))
builder.addRow([selected]+[newData.getValueAt(r, c) for c in crange])
return builder.build()[/code]Assuming the original dataset is in the root container in a property named ‘Source’, use this expression on the table:toDataSet(objectScript( 'project.dataset.addSelectColumn(binding, "ID #", args[0])', {Root Container.Source}))Untested, but that should get you started. The objectScript() expression function is part of my Simulation Aids free add-on module.

Thanks Phil! This worked beautifully and the table retained all the functionality I need.

I ran into a new issues now. I have a checkbox in the corner that will check/uncheck all rows. I need it to work on filtered data so I wrote a script that looks at the “View Dataset” to determine if a row is included in the filtered data then looks at the unique “id” column to determine which rows to then select in the data property. My problem is I’d really like to hide the “id” column which then removes it from the “View Dataset” and the script can no longer determine which rows in the data property to select. Is there any way to visually hide a column while retaining it in the “View Dataset”?

Thanks!

Have you tried hiding the column using the table customizer?

Yes but that also removes it from the “View Dataset”

Hmmm. Try using a width = 0 for that column by editing the column attributes dataset directly.

There doesn’t appear to be a width aspect in the column attributes dataset but when changing the column sizing property or using .setColumnWidth the smallest it will shrink is 71 regardless if I specify a smaller number. I’ll look into messing with the scripting/java.

I got it by messing with the various numbers in column sizing. I think I figured out what about 1/2 the number represent. Filtering works great and looks good!