Loredra L
Loredra L

Reputation: 1553

DataTable slow when drawing multiple of them

I have a web application that require multiple redraw of DataTable's instances. Each of them has very small datasource but when I do a performance checking of a normal instance

var table = $("#Table").DataTable({
    "data": smallData
});
$("#Table").clear():
$("#Table").rows.add(otherSmallData).draw();

It already took 200ms. In my case, updating all instances would took 2 seconds(2 seconds browser-freezed). Is there anyway to do it client-side smoothly?

Upvotes: 0

Views: 1467

Answers (2)

annoyingmouse
annoyingmouse

Reputation: 5689

You're already creating a reference to the table with jQuery, what happens when you use that instead of digging into the DOM? Like this:

var table = $("#Table").DataTable({
    "data": smallData
});
table.clear().rows.add(otherSmallData).draw();

Upvotes: 1

Gyrocode.com
Gyrocode.com

Reputation: 58860

Try using deferRender option for deferred rendering for additional speed of initialization.

var table = $("#Table").DataTable({
   "data": smallData,
   "deferRender": true
});

Upvotes: 1

Related Questions