Regarding deferRender & building datatables
Regarding deferRender & building datatables
Am I correct in thinking that the deferRender option doesn't do anything when you build the DataTable from an Ajax 'success' callback? in other words, if I set up the DT early on, and later drive the contents through a button click to call the Ajax function that will populate the DT through an iterative $each function... illustrated below:
$.ajax({
type: "GET",
cache: false,
data: params,
url: ajaxUrl,
contentType: "application/json; charset=utf-8",
success: function (boxes) {
$.each(boxes, function (i, data) {
var box = new boxView(data); // does mapping
dt.row.add(box); // adds to dt
});
}
});
I have about 10k records, I don't want to go through serverSide so I figured I'd try deferRender without much luck in the way I need to build the data tables.. looking for confirmation that this doesn't work this way, or some help on how to set it up..
Thanks in advance!
Answers
Figured I'd share the dt instance setup code below:
Sounds like, per the docs,
deferRender
works with data loaded via theajax
option or thedata
option.Without know more about what is triggering the data load and when I would look at the following options:
ajax
ordata
to load the data.row.add()
in the loop build an array then once the loop is complete either initialize Datatables using thedata
option or userows.add()
. Not sure but supplying an array of data torows.add()
might be more efficient then usingrow.add()
individually.Kevin
Kevin - thank you, I'll give that a shot and see if it speeds things up..
it would be great to get more insight to how deferRender was implemented and how it's supposed to help optimize loading.. I don't want to handle sorting/filtering/paging myself, that would defeat a lot of the purpose here.
This discussion may help:
https://datatables.net/forums/discussion/comment/136292/#Comment_136292
Kevin
So I have this modification in place.. still slow to load, I'm guessing it's the mapping of the objects in the result set … if I need to manipulate the data before I post it to the table, does deferRender yield itself useless? there's no logic check but instead mapping data from the JSON to observable objects.. I cant just populate the data as is from the ajax callback.
I even set the autoWidth property to false! … truly appreciate the fast responses in this forum, thank you in advance.
You can output some timers like this example to see how long it takes for the for loop. Start the timer before the for loop and use console.log after the for loop (before the
return json
). This should help you determine where the problem is. Also turn deferRender off to see if there is a different.http://live.datatables.net/fomaqofu/1/edit
Kevin
Thank you for the last reply, the timers for some reason don't seem to vary much in my console output. i'm seeing slow load times with either approach and thinking perhaps it's to do with the declaration of a new boxView object for each datarow.
Is there another way to load the DT with special objects not just a generic JSON response object? each one of my boxView objects contains observables that can be updated through other page events later - hence they don't remain statically drawn was the idea. but it appears to be a hog... I don't want to iterate through all 10,000 rows on load, it kills my client machines.
I'm not familiar with boxView but if you only need it for the rows that are visible then maybe
rowCallback
orcreatedRow
might be the place to enable it. The thought is with one of those callbacks you can enable the observers as the page is displayed.If this
json[i] = new boxView(json[i]);
doesn't manipulate the data then a good test might be to remove the loop and just return the json data. This will give you an indication of how long Datatables needs to build your table.Kevin