question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Button click event is sending the wrong props.index after insert new row in datatable component

See original GitHub issue

Steps 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

https://codepen.io/tmmsmoreira/pen/YrBRBe

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
johnleidercommented, Oct 20, 2017

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

0reactions
husaytcommented, May 3, 2019

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:

  @click="doAction(items.indexOf(item))"
Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found