Pagination is getting reset to default ? Any alternative way

Pagination is getting reset to default ? Any alternative way

supercoolsupercool Posts: 7Questions: 4Answers: 0

Hi

I've been fruitlessly been trying to get jQuery.dataTables to allow me to update the data in the table using Javascript.

I have a parameter called data that represents the data to display in the table. It is passed into a function.

I would have thought that the way to update the data would be like this:

// I checked that the new data is returned by $table.data() afterwards
$table.data(data);
// Now that the data is updated, redraw the table.
$table.fnDraw();
Nothing seems to happen when the above code runs. What am I doing wrong?

I have no trouble using fnUpdate to update the data in individual rows, so I find this particularly perplexing.

Update: After giving this some more careful research, I found that I can almost achieve the desired result by doing the following:

$table.fnClearTable();
$table.fnAddData(data);
$table.fnDraw();
However, the problem with the above is that the user loses his place in the pagination and has to navigate back to the page he was on.

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,383Questions: 1Answers: 10,449 Site admin

    Using the new API you would call draw() with the parameter false. In the old API you would use fnDraw likewise (and also in fnAddData use the parameters to not redraw).

    Allan

  • supercoolsupercool Posts: 7Questions: 4Answers: 0

    I've tried using the draw function, and it doesn't seem to do redraw anything. Only when I use fnAddData or fnClearTable or fnUpdateRow does it seem to do anything.

  • allanallan Posts: 63,383Questions: 1Answers: 10,449 Site admin
    Answer ✓

    Can you link to the page so I can debug it please?

    I presume when you use draw() you are using the access constructor for the new API - i.e. $().DataTable() (capital D).

    Allan

This discussion has been closed.