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

onRowsDelete

Open RutulDarji opened this issue 7 years ago • 9 comments

onRowsDelete: (data) => { console.log( data ) }, i have done this. i want to customize that and don't allow to delete rows of that table How can i do that??

or if i select any rows i want to disable the delete button ?? i tried with customize toolbar still its not working

RutulDarji avatar Feb 18 '19 07:02 RutulDarji

It's too late to make any changes in onRowsDelete method. You can solve that using custom ToolbarSelect like this:

options = {
   customToolbarSelect: (selectedRows, displayData, setSelectedRows) => (
      <React.Fragment/>
   ),
}

React.Fragment will not add unnecessary elements to your DOM.

ljacho avatar Feb 18 '19 12:02 ljacho

why it is too late ?

RutulDarji avatar Feb 19 '19 09:02 RutulDarji

@RutulDarji because your rows already disappeared from the table didn't they? onRowsDelete is callback after delete actually. Isn't solution with customToolbarSelect suitable for your case?

ljacho avatar Feb 19 '19 09:02 ljacho

I am working on local machine so delete rows not affect that much

RutulDarji avatar Feb 19 '19 15:02 RutulDarji

customToolbarSelect works for me but what happen after i completed my task i have clear all my states but the previously selected times like .. i have selected 2 rows and it shows on header that 2 rows selected after the completion of the task i have cleared all my states so in react it will re render but the 2 rows selected still stay at table header.. I found out why this happend because onRowsSelect: (cur, all) the value of all doesn't chaange event after the refresh

RutulDarji avatar Feb 20 '19 09:02 RutulDarji

There is another option rowsSelected - you can map it to your state and according to your words clear that as well

ljacho avatar Feb 23 '19 00:02 ljacho

Sorry, I don't understand. Example: columns[id,value] data are from external API and it will be something like this: {id:123, value:value1}{id:678, value:value2} ecc... Imagine you have many rows ... With onRowsDelete I have back only the index of the table and the array of selection.... onRowsDelete:(rows)=>{console.log(rows)} I have in console data: Array[1] 0: Object index: 1 dataIndex: 1

but i need to have my id not the index of the row of the table.... suppose I selected my first row I'd expect something: data: Array[1] 0: Object index: 1 dataIndex: 1 id:123 value:value1 so that I can remotely delete the record with the selected id

or alternatively Can I recover with index that I have in return from onRowsDelete the value of my id column in the table?

matteo1976 avatar May 01 '19 14:05 matteo1976

I've got a PR up that might help. The idea is that returning false from onRowsDelete will prevent a delete action from taking place. There will be an example in the code to demonstrate this as well.

gabrielliwerant avatar May 01 '19 18:05 gabrielliwerant

I've got a PR up that might help. The idea is that returning false from onRowsDelete will prevent a delete action from taking place. There will be an example in the code to demonstrate this as well.

Thank You @gabrielliwerant

RutulDarji avatar May 03 '19 12:05 RutulDarji