jQuery DataTable pagination refresh

I am using DataTable for pagination in my table. The content in the table is loading by making ajax request. The problem is that I’m using my own functions that fill table with data(in other words, I operate with table’s DOM manually). So is there a way to reload just pagination? I have tried reading the API, but all I found is ajax API, and it doesn’t fit my code since I want to operate with data by myself.
Thanks in advance, hope the question is clear.

Answer

I found an answer. As I found out the DataTable parse the table when first DataTable() is invoked and holds it internally. So I have to clear that data before my ajax request:

var table = $('#mytable').DataTable();
table.clear();

Then I add data and draw it in a cycle:

for(var k in data) {
    // do smth with data
    table.row.add([
        k.field1,
        k.field2
        // ...
    ]).draw();
}

Leave a Reply

Your email address will not be published. Required fields are marked *