Making a table column editable

I have been trying to make a table column editable but it does not seem to work. The table is attached to a named query. Also how do I hide a column?

If you want to be able to make a table column editable right click on the table and select on Customizers > Table Customizers > Editable and check whatever columns you want to make editable. The same applies to hiding columns. It can all be done in the Table Customizer.

I donā€™t see the option when I right click on the table.

To make a cell editable in Perspectiveā€™s table component, you need to make the columnā€™s value an object, rather than a literal value; see the example in the seeded table component - the ā€˜Cityā€™ for Helsinki is a static string, but for Folsom itā€™s an object with (in this case) three keys. The two vital ones are the value (ā€œFolsomā€) and the editable flag (set to True). see @anjorogeā€™s comment below.

However, unfortunately at present table cell editing hasnā€™t been implemented - the Vision concept of ā€˜Extension functionsā€™ is going to be carried over in some respect.

I believe the above solution is for vision components but for perspective components you can make all the cells of a column editable by configuring the column config (columns prop). You can also make individual cells editable, which overrides whatever is configured in the column config.for information you can go to the below link.

http://forum.inductiveautomation.com/t/feedback-new-perspective-table/

it looks like the feature has not been implemented yetā€¦ I tried the following settings and I can not edit the columns yet. I tried it on 2 columns.

Hi,

Column configs control the ordering, number of columns displayed, what columns are displayed, and an individual columns configuration. Thereā€™s no way to know what column config is associated with what data column unless you specify this using the configs ā€˜fieldā€™ prop. The ā€˜fieldā€™ prop should correspond to the key in the key value pair of your data, assuming it is a dataset or an array of objects. For example, [{ city: ā€˜Folsomā€™, state: ā€˜Californiaā€™ },ā€¦] would require that the ā€˜fieldā€™ prop of the column config for your city column be ā€˜cityā€™ in order to associate the column config with the data.

Hope that helps.

-Yousuf

2 Likes

But I am still not clear about how to make the column editable.

Table editing isn't yet implemented.

I got it. Any ETA on when it will be implemented? I am also trying to render a view in a cell using the viewpath property and it does not seem to work either

Try linking the column config with the desired column using the ā€˜fieldā€™ prop, as I suggested earlier.

Editing a cell is currently possible, however, we currently do not have anything implemented to handle these changes. Edits are currently being logged to the browser console as an example of what will become available. We are currently working on implementing extension functions in order to handle these edits, which you can expect soon.

Please refer to http://forum.inductiveautomation.com/t/feedback-new-perspective-table for the latest unofficial docs, news on the table component, and the answer to many of your questions.

-Yousuf

I donā€™t know if thereā€™ll be an easier way to do this but hereā€™s my solution thus far. To enable editing for select columns Iā€™ve converted the incoming data (a dataset thatā€™s the result of a query) to a list of dictionaries. each row is: {ā€˜column nameā€™:{ā€˜valueā€™: 10,ā€˜editableā€™:True}.

# convert dataset to dict
editableCols = ["firstName","lastName"]
ds = value
colNames = ds.getColumnNames()
d = []
for i in range(ds.rowCount):
	rowDict = {}
	for col in colNames:
		editable = False
		if col in editableCols:
			editable = True
		rowDict[col] = {"value":ds.getValueAt(i,col),"editable":editable}
	d.append(rowDict)
return d
1 Like

Running on Version: 8.0.0 (b2019040718)

Quick workaround:
Go to your table, left-click, Configure Event... > Component Events > onEditCellCommit
Adapt the following script according to your needs, in my case I was toggling a boolean column called 'PRINT':

tbl = self.props
state = tbl.selection.data[0].PRINT == 'true'
tbl.data = system.dataset.setValue(tbl.data, tbl.selection.selectedRow, tbl.selection.selectedColumn, not state)

I haven't tested it thoroughly but it seems to be working fine. Remember to leave the option editable turned on (table.props.columns.editable).

I am experiencing the same issue as described above, but with version 8.1.11 (b2021101912).

Iā€™ve attempted to drop a new table onto a view and change nothing (e.g. leave all settings as default and sample data intact).

When I try to edit the first cell (Folsom), which already has editing enabled, any changes made to the cell value fail to commit.

I ended up adding an onEditCellCommit script similar to @apereira above (except using dictionary instead of dataset):

tbl = self.props
value = event.value
tbl.data[tbl.selection.selectedRow][tbl.selection.selectedColumn] = value

Has anyone else experienced this issue in 8.1.11?

1 Like

What makes you think the script is optional? (It isnā€™t.) Maybe the docs need to be more clear.

Optionally, use event.row for row index & event.column for column name:

self.props.data[event.row]['value'][event.column] = event.value

Note that you may need to omit ['value'] if it is not in your dataset.