Hi all,
I'm running into an issue with getting an accurate row index when a user is interacting with a table. This table has both sorting and filtering enabled and I am able to access the filtered data with some code like the following:
# convert table data and filtered data into a standard list
data = []
if not self.props.filter.results.data:
for i in self.props.data:
data.append(i['value']) #some styling in the row, therefore we need to access 'value'
else:
data = self.props.filter.results.data
This works as intended by setting data to the filtered results when there are any. However, I cannot find where the sorting comes into play. For example, using the table's onEditCellCommit
event I am able to get which row this event happened on. But the issue comes into play when I try to get that row's data while it is being sorted as it returns the original table's row value.
Does anyone have some input on where the sorted data goes or how to get accurate event data?
I'd have to see your onCellEditCommit
script to be sure, but perhaps you're using rowIndex
where you should be using row
.
In the table event scripts, the row
is the index in the original data prop, while the rowIndex
is the index on the visible (sorted/filtered) data. You should either use rowIndex
with the filtered data, or use row
with the original data.
1 Like
I am building out the data
list with the code above, which is a bit clunky because I am applying styles to each individual row of the table. Then in order to access the table data, I am referencing that data list with data[event.rowIndex]
, where it does seem to reference the row that I am interacting with but not the data. Are you thinking the issue is in the way I am building out that data list and referencing that over the actual table data property?
Are you trying to assign values to the rows in your data
variable? If you want to modify your original data, you'll have to assign to the original data prop. Your data
list might work for reading values, but it won't work for writing.
Is there a reason you're building out your data
list first? Could you use:
self.props.data[event.row]['value']
No, I am using the data that is in the row receiving the edit to fill out parameters in a query that updates the relating row (via UUID's) in a database.
The main reason I build out my data
list is that I also have filters enabled on this table, and it let me standardize references to where the data should be later on in the script.