How to avoid several redraws when adding+removing rows by ja code?

How to avoid several redraws when adding+removing rows by ja code?

KarloKarlo Posts: 34Questions: 10Answers: 0
edited May 2019 in DataTables


After some time then the data rows are already loaded and visible, I sometimes have to amend the data by JS code. This may include adding a few rows and also removing some rows, sometimes in one method call.

Essentially what I'm doing is:

// add some rows
for (var _i = 0; _i < entiriesToAdd.length; _i++) {
// remove some rows
for (var _i2 = 0; _i2 < idsToRemove.length; _i2++) {
  var s = "#MY_ID_PREFIX_" + idsToRemove[_i2];
// finally redraw

This generally works, but the problem is that I see DataTables is doing intermediate redraws, which makes the bowser view blinking ugly and waste time. I was expecting that only one redraw is triggered (by the last code line)?

This question has an accepted answers - jump to answer


  • colincolin Posts: 8,647Questions: 0Answers: 1,446
    edited May 2019 Answer ✓

    Hi @Karlo ,

    As show in this example, row.remove() and row().add() won't cause any redraws - you need to manually do the redraw yourself.

    If you're seeing flickering, it may be because you've got other event handlers being called. To minimise the flickering, you could try calling rows().remove() and rows.add() to remove and add in bulk, rather than individually. But if you want to remove the flickering entirely, please could you link to your page or a test case, or modify my test case to demonstrate the issue.



  • KarloKarlo Posts: 34Questions: 10Answers: 0


    I identified a problem in handling the data on my side, so this seems to be no issue in DataTables.

    Thank you very much!

This discussion has been closed.