Change cells value in Datatables in selected rows only

Change cells value in Datatables in selected rows only

AbuMaizarAbuMaizar Posts: 14Questions: 6Answers: 1
edited June 2017 in Free community support

I m trying to target some cells values only in selected row or rows. I have tried a code as explained in the following snippets but it keeps targeting the first row, not the selected one,

$("#btn1").click(function() {
var rows_selected = tablenest.rows({
selected: true
});
$.each(rows_selected, function(i, v) {
tablenest.row(rows_selected).cell(':eq(3)').data("").draw();
tablenest.row(rows_selected).cell(':eq(4)').data("").draw()
});
return false;
})

i have live ex here

Answers

  • AbuMaizarAbuMaizar Posts: 14Questions: 6Answers: 1
    edited June 2017

    bingo
    tablenest.rows({ selected: true }).every(function (rowIdx, tableLoop, rowLoop) {
    tablenest.row(this).cell(rowIdx,2).data("").draw()
    tablenest.row(this).cell(rowIdx, 3).data("").draw()
    });

  • allanallan Posts: 61,439Questions: 1Answers: 10,053 Site admin

    Almost perfect. I would suggest:

    tablenest
      .rows({ selected: true })
      .every(function (rowIdx, tableLoop, rowLoop) {
        tablenest.cell(rowIdx,2).data("");
        tablenest.cell(rowIdx, 3).data("");
      })
      .draw();
    

    as a slight modification. It will run faster :)

    Allan

This discussion has been closed.