ColReorder / rowCallback / serverSide

ColReorder / rowCallback / serverSide

olemoignolemoign Posts: 3Questions: 2Answers: 0

I'm having problems with colReorder and rowCallback. After a colReorder, dataTables resets the cells content, removing the impact from rowCallback.
After reading https://datatables.net/forums/discussion/31083/colreorder-and-rowcallback-dont-play-nicely-with-each-other this seems to be normal.
What I don't understand is, if I follow the JSFiddle in the thread ( https://jsfiddle.net/d6p2b/z8meddv6/ ), the bug disappeared! Has it been fixed some time ago? If so, why am I still seeing it? Because I use server-side dataTables?

I have created another JSFiddle that reproduces the error, on 1.13.11 and 2.0.2: https://jsfiddle.net/olemoign/w6q7sag1/9/

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    Answer ✓

    I'd strongly encourage you not to use rowCallback to modify the content of the cells. DataTables knows nothing about those changes, so you run into problems if you do something that invalidates the data and results in the contents being redrawn, which is what you are seeing here. ColReorder 2 was reworked a bit, which is probably why you are seeing this.

    I workaround would be to do a draw after reordering to trigger rowCallback again:

    table.on('columns-reordered', function () {
      table.draw(false);
    })
    

    However, I'd very much encourage you to use a data rendering function if you need to modify the cell content.

    Allan

Sign In or Register to comment.