Can't change cells content with DataTables 2 (works with DataTables 1)

Can't change cells content with DataTables 2 (works with DataTables 1)

andrew45andrew45 Posts: 24Questions: 8Answers: 0

That's the problem I came across while upgrading my code from DataTables 1+ to 2+.

When I use DataTables 1.10-1.13, it works perfectly well. I can changed content in every cell of a column I need:

table.cell(':eq('+i+')', 3).data("changed");

Test case with DataTables 1+ (works OK): https://live.datatables.net/hucifoba/1

But when I use DataTables 2+, I can changed only cells on the FIRST page of a column. Other pages remain unchanged. Moreover, I get a "Cannot read properties of undefined (reading 'row')" error.

Test case with DataTables 2+ (works only on the first page): https://live.datatables.net/gibukomi/1/edit

Is it a bug? What should I do?

This question has an accepted answers - jump to answer

Answers

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

    Not a bug - it is because DataTables 2 enables deferRender by default, but your code depends on the cell nodes being present to be selected (through the use of a jQuery selector - the :eq()).

    Using a row index selector works just fine.

    So you could simply add deferRender: false and it will go back to the v1 behaviour, or you could look into updating the code to allow it to work with deferred rendering enabled. It will depend exactly on what you are doing for the best way to do that.

    Allan

  • andrew45andrew45 Posts: 24Questions: 8Answers: 0

    Yes, deferRender: false did the job. Thanks for other options.

Sign In or Register to comment.