Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 428
Timofey Avatar asked Mar 10 '26 09:03

Timofey


1 Answers

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();
}
like image 137
Timofey Avatar answered Mar 12 '26 22:03

Timofey



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!