Remove some rows from selected array

Remove some rows from selected array

PinnkasPinnkas Posts: 2Questions: 1Answers: 0
edited August 2019 in Free community support

Hello,

I am using Datables version 1.10.18 with Select v1.3.0 plug-in.
I have selected some rows by user and I need to remove few of them by some criteria. I can not find how can I do it.
Here is my code:

var dTable = $('#myTable').DataTable({
    "searching": false,
    "paging": false,
    "info": false,
    columnDefs: [{
        "targets": 0,
        orderable: false,
        className: "select-checkbox",
        checkboxes: {
            "selectRow": true
        }
    }],
    select: {
        style:    "multi"
    },
    "order": [[ 1, "desc" ]]
});

$("#btnOK").click(function(e){

    var selRows = dTable.rows({selected:true});
    var selData = selRows.data();
    var selCount = selData.length;

    for (var i=0; i < selCount; i++){

        var idx = dTable.row(selRows[0][i]).index();
        var TD = dTable.cell({ row: rowIdx, column: 0 }).node();
        var TR = TD.parentNode;

        if (TR.dataset.id == "remove-This-row") {
//          dTable.row(idx).remove().draw();  // removes wrong row
//          dTable.row($(TD).parents('tr')).remove().draw();  // removes also wrong row
//          dTable.fnDeleteRow(idx);  // function not found - although I do find this function in Datatables.js
        }
    }
});

How can I remove correct rows?

Answers

  • PinnkasPinnkas Posts: 2Questions: 1Answers: 0

    I found the problem. Actually the command:

    dTable.row(idx).remove().draw();

    removes the right row. But after the row has been deleted all the rows below it changes indexes. So I have to remove rows starting from biggest index first.

    Thank you anyway.

This discussion has been closed.