mui-datatables icon indicating copy to clipboard operation
mui-datatables copied to clipboard

Different item is selected when selected item is deleted

Open Ic3xX opened this issue 6 years ago • 7 comments

Current Behavior

Let's say i want to delete one or more items, the current behavior is to select other items if the datasource has changed and items are no longer available.

Expected Behavior

I don't know if this is a bug but i expect there is no selection active after deleting items.

Your Environment

Tech Version
Material-UI 4.11
MUI-datatables 3.4.1
React 16.13.1
browser Chrome 84.0.4147.135

Ic3xX avatar Aug 21 '20 12:08 Ic3xX

I don't understand. This is no selection active after deleting an item.

patorjk avatar Aug 23 '20 15:08 patorjk

I tried to reproduce in a codesandbox but it's working as expected so i will close the this issue. This is likely related to my own code.

Ic3xX avatar Aug 24 '20 10:08 Ic3xX

Can you take a look at the following sandbox: https://codesandbox.io/s/wandering-browser-f0em9?file=/src/App.js

As i can see my issue is related to the customToolbarSelect;

Ic3xX avatar Aug 25 '20 15:08 Ic3xX

This is interesting. When the data is updated, the internal rowsSelected and rowsExpanded state values should reset. Your updates are causing a re-render, but for some reason those values appear to be staying intact. I'll have to investigate this more later.

As a workaround, you can use the option "rowsSelected" and manually indicate which rows are selected. The only catch you is have to use the onRowSelectionChange callback to make sure this array stays properly updated.

patorjk avatar Aug 25 '20 16:08 patorjk

Thank you for the update, i will use the workaround for now.

Ic3xX avatar Aug 26 '20 05:08 Ic3xX

I have also experienced this issue. The interesting thing is that in case data field is updated, then selection indeed is nullified, but ir row in data is deleted, then the selection stays active.

PresentProgrammer avatar Feb 10 '21 20:02 PresentProgrammer

updated my lib and seeing this behavior now too

chrishawn avatar Feb 22 '21 18:02 chrishawn