Complete Delete of row when using RowReorder?

Complete Delete of row when using RowReorder?

ChakronSAChakronSA Posts: 4Questions: 1Answers: 0

I have a table that has rowReorder enabled. Users also need to be able to delete a row from that table. I'm having trouble fully deleting a row. Example:

https://jsfiddle.net/ChakronSA/c45eL717/

To recreate:

  1. Click "Delete" next to "Name 3". This deletes the row and updates the order labels.
  2. Drag "Name 4" so it's above "Name 1". This works, but now the labels are wrong (should show 1, 2, 4, 4). I assume this happens because rowReorder still thinks the "Name 3" row is there.

How do I make the underlying storage aware that a row within the rowReorder object has been removed? Thanks!

Replies

  • allanallan Posts: 63,075Questions: 1Answers: 10,384 Site admin

    The issue is here:

        $.each($('#myTable tr td:first-child'),function(index,val){
          $(this).html(index+1)
        });
    

    DataTables doesn't know that you have done it - and it continues to use its cached data.

    You could possibly invalidate the rows (rows().invalidate()) to re-read from the data source (the DOM in this case): https://jsfiddle.net/c45eL717/1/ . Or use cell().data() rather than jQuery / DOM to update the data.

    Allan

  • ChakronSAChakronSA Posts: 4Questions: 1Answers: 0

    Allan, thanks a lot for the help. I figured it was something like that but I was having difficulty invalidating the rows (apparently it was that simple)! The number rows in my table will always be small and what you've posted in the jsfiddle will work.

  • allanallan Posts: 63,075Questions: 1Answers: 10,384 Site admin

    apparently it was that simple

    Only if you know how ;-).

    Good to hear that will work for you.

    Allan

This discussion has been closed.