Identifying the row which is about to be / has been deleted using the preRemove and remove events

Identifying the row which is about to be / has been deleted using the preRemove and remove events

jladburyjladbury Posts: 34Questions: 9Answers: 0
edited May 2018 in DataTables 1.10

How can I find which row is the subject of these events? Debugging these events with the Chrome debug tools, I find e.currentTarget.s.editFields[1].data contains what I want, but this seems a bit hackerish in the absence of any documentation that I can find.

This question has an accepted answers - jump to answer

Answers

  • Tester2017Tester2017 Posts: 145Questions: 23Answers: 17
    edited May 2018

    Just find the selected rows with table.rows(".selected").

    Because if you want to delete a row (or more) you have to select them. Then you click on delete, and delete will only affect the selected row(s).

    You can make an array of the id's of the selected row(s) and then wait for the server response. If the response if an "empty" JSON string then you know that all rows selected have been removed on the server. If the response holds some info, then you have to grap the id's and check with your former created array to check which row has been deleted and which one(s) not.

  • jladburyjladbury Posts: 34Questions: 9Answers: 0

    Thanks for your response.

    However, I am working in client only - no server is involved, hence my interest in using the events.

    Although the general approach would work, it would be a bit messy to have to store info about selected rows in preRemove, and then deal with them later in remove.

    If someone (preferably Allan!) could point me at some information about e.currentTarget.s.editFields, or other information available in the remove event, I would be most grateful!

    Alternatively, if I can be sure that, failing a system crash, the selected rows found in preRemove will indeed be deleted, I can simply use that event for my purposes.

  • allanallan Posts: 61,446Questions: 1Answers: 10,054 Site admin

    The s object is Editor's internal settings object, so it isn't documented anywhere other than the code since it isn't designed to be publicly accessed. You want to avoid using it, since it can change between versions.

    You could use modifier() to get the value(s) that were used to trigger the edit (and then use them to select the target rows) - e.g.:

    editor.on( 'preRemove', function ( e, json ) {
      var rowsData = table.rows( editor.modifier() ).data();
      ...
    } );
    

    What is it that you want to do in the event?

    Allan

  • jladburyjladbury Posts: 34Questions: 9Answers: 0

    I want to update another data structure that needs to be synchronised with the table. That is easy in the create and update events, because the JSON data contains the information I need - but in remove it is, unsurprisingly, empty.

  • allanallan Posts: 61,446Questions: 1Answers: 10,054 Site admin
    edited May 2018 Answer ✓

    Got it. Another option would be to do it in postSubmit - check that it was a remove action and then process the data that was submitted to the server (which will include information about the rows submitted).

    Allan

  • jladburyjladbury Posts: 34Questions: 9Answers: 0

    Perfect! I still have my DevTools open and can confirm this is just what I need.

    Thanks very much!

This discussion has been closed.