Commit value of Perspective Table cell Edit on Click outside or other cell

Hi Team,

I have a requirement to Edit the perspective Table cell. The table is SQL table.I have done that by writing the event scripts on EditCellCommit. After edit I need to press the enter to store the value in the cell. Now I want to commit the cell if I clicked outside or another cell. Is that achievable?

Yes, but I think I’ve only achieved it by using a custom view for that cell with a TextField and .onBlur() handler.

Thanks for the reply

May I know little detail about that… So that I can try

Currently I have used the following script

               
            # Convert dataset to Python list
                pyData = system.dataset.toPyDataSet(self.props.data)
            
                # Get edited cell details
                rowIndex = event.rowIndex
                colName = event.column
                newValue = event.value
            
                # Get primary key from the edited row
                idValue = pyData[rowIndex]["tankNo"]
                # Call Named Query
                system.db.runNamedQuery("tst", {
                    "Tankname": newValue,
                    "Tankno": idValue
                })
            
                # Refresh table data (important if query binding)
                self.refreshBinding("props.data")

Does it work with Focus Events () onBlur ?

Create a custom view for the table column and apply it to the table using the table column viewPath property. Create a parameter to the view named rowData, then place a TextField in that view with its value bound to view.params.rowData.tankNo. Add an onBlur handler to the TextField that runs the query to update the database, and then calls system.perspective.sendMessage('refresh-table'). Add a message handler for refresh-table (or whatever you call it) on the table that invokes self.refreshBinding("props.data").

Note that the cell will then always be rendered as a TextField, unless you do what I do and create a label for it, and toggle their views (use onClick on the label to make the TextField appear, and use the onBlur handler to switch back to showing the label).

I’m interested in this too but it’s not worth applying views to every column in all my tables.

onEditCellCommit is great when the user hits [Enter].
Testing with other events like onKeyPress, onRowClick, onComposition* and even change script events to the editingCell column and row properties don’t have a way to capture the uncommitted value.

Yes, it shouldn’t have to be so difficult.

1 Like