Deleting wrong rows...?

Deleting wrong rows...?

driekusdriekus Posts: 2Questions: 1Answers: 0
edited July 2016 in Free community support

Hi all,

Below is a part of the delete function I'm using in my project. Big bug is that when selecting multiple rows in datatable the first is always deleted properly but for the rest I'm getting back the wrong data (ids) from datatable.

The code I'm using:

dt.rows('.selected').every(function (rowIdx, tableLoop, rowLoop) {
      var data = this.data();

      // Callback to registered removeRow function
      settings.removeRow.action(dt, data);

      dt.row(rowIdx).remove().draw();
});

Am I doing something wrong heir? Or is it a bug in Datatables?

Kind regards,
Henry

Answers

  • driekusdriekus Posts: 2Questions: 1Answers: 0

    Fixed it myself. The remove.draw() has to be done at the end of all row removeal!

                  var dataRows = dt.rows('.selected').data();
    
                        dt.rows('.selected').every(function (rowIdx, tableLoop, rowLoop) {
                          var data = dataRows[rowLoop];
    
                          // Callback to registered removeRow function
                          settings.removeRow.action(dt, data);
    
                          // Redraw table when last row has been removed!
                          // else wrong rows are being removed!
                          if (rowLoop >= (dataRows.length - 1)) {
                            dt.rows('.selected').remove().draw();
                          }
                        });
    
This discussion has been closed.