i’m facing an issue, again:
I’m trying to run a script in a ‘Table’ component with the event handler ‘onPropertyChange’, and i’m having trouble because sometimes the table returns me 3 changes on propertyName == “selectedRow” even if i changed it just once.
Here is what i did:
I’ve create a Memory Dataset TAG which is linked to a TABLE.data, in order to display it’s value.
I’ve created a button that adds a row into this Dataset TAG.
If you click the button, it has to add a new line into the Dataset TAG, and then, the button, has to select the row it just inserted.
Meanwhile, because the ‘selectedRow’ changed, the table runs the ‘onPropertyChange’ script, that have to check if the event.propertyName “selectedRow” has changed and launch a function.
What i’m facing:
While adding the first row to the dataset TAG and selecting the new row into the Table, it works as expected.
If i add the second, third, fourth, etc…it adds the row and it select it, but the ‘onPropertyChange’ script run 3 times instead of 1, because it get that the “Selected” row changed from -1 to 0, from 0 to 1 and from 1 to 2, so my function runs 3 times instead of 1.
Below, you’ll find the output of the console, where i printed both the result of the function and the selectedRow .newValue and the message that it’s inside of my function “aggiungiStep()”
//Getting dataset from the table
Dataset = event.source.parent.getComponent(‘Table’).data
// Add new row to the dataset
Row = [“Test”]
New_Dataset = system.dataset.addRow(Dataset,Row)
// Get the new line index
Row_Select = New_Dataset.rowCount - 1
// Write the new dataset to the TAG
// Check if .data lenght changed and select the row based on some values
if event.propertyName == “data”:
Programma_DS = event.source.data
Riga_Sel = event.source.selectedRow
Old_DS = event.oldValue.rowCount
New_DS = event.newValue.rowCount
if Old_DS < New_DS:
event.source.selectedRow = Riga_Sel + 1
if New_DS >= 1:
event.source.selectedRow = Riga_Sel -1
event.source.selectedRow = -1
// function which is called if selectedRow changed
// event selectedRow
if event.propertyName == “selectedRow”: