Button click event is sending the wrong props.index after insert new row in datatable component
See original GitHub issueSteps to reproduce
I have a datatable with some data and each row has a ‘view’ and a ‘delete’ button.
I want to be able to add a new row to that table. So, to do that, I created a button that push
some data to my datatable items array.
After doing that, a new row is added and it is sorted the right way. But when I press the ‘view’ button of that new row, it shows me the content of previous the row in that same position.
Versions
0.16.6
What is expected ?
After pushing new content to datatable items array, the props.index
that is sent as an argument to the click event button must be the right one.
What is actually happening ?
The props.index
is wrong and shows the wrong row data.
Reproduction Link
Issue Analytics
- State:
- Created 6 years ago
- Comments:8 (3 by maintainers)
Top Results From Across the Web
React - click data on table returns wrong index of row and ...
After clicking a table cell, i need function to know exact row index and column index of it. In my case, i have...
Read more >Can we catch rowclick event lightning-datatable just click
yes if you column type as button or icon button it will be displayed on each row and you can get the clicked...
Read more >How To Handle Async Data Loading, Lazy Loading, and Code ...
You'll load data using an asynchronous function that simulates a request to an external data source. First, create a component called ...
Read more >Using material-table in React to build feature-rich data tables
Let's review how to create tables in React using one of the best and most feature-rich libraries available: material-table.
Read more >Row Selection - React Data Grid
rowMultiSelectWithClick : Set to true to allow multiple rows to be selected with clicks. For example, if you click to select one row...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
The problem is that the index that comes back from the scoped slot does not directly correlate to the index of your locally scoped item array. When the data-table sorts, it doesn’t maintain the original array order, and has different indexes for the new sort.
You can observe this behavior by clicking the view button, resorting the table, and clicking the same position. It will display the same item because your local items array has not been mutated in the exact same manner as the table sort.
I’m attaching a different way to handle this, hopefully it can help you. https://codepen.io/johnjleider/pen/JrzYmE?editors=1111
Yes, indeed seems like current index is both useless and misleading. Would be great to a) rename current index to displayIndex b) add a new index to scope c) also clearly specify in docs what is each index is for.
meanwhile I will use this workaround to find index: