When testing my data table with 60,000 rows and 6 columns (defer render is turned on), we encountered a lag when typing in a custom search box (not the default search that Datatables provides). To clarify, what is happening is that I would start to type in "zuz" into the custom search box, after typing in the "u", it should take a second to actually appear and does not appear instantaneous.
Basically, my current code has it so that it does a search and re-draw after each keyup event.
searchBoxOnKeyup: function(e) {
var table = this.getCurrentTable();
table.search($(e.target).val()).draw();
}
I think what's happening is that the table draws before my next character input so that the next character takes longer to actually show up in the search box.
I've actually used the built in search box and it has no problem dealing with the 60,000 rows and showing the input without any lag. The reason that I can't use the default built in search box is because the UI design has the search box in a different location with other controls next to it (ex: select and a checkbox)
What I have tried so far is throttling the draw action:
var search_term = $(e.target).val();
var search = $.fn.dataTable.util.throttle(
function ( search_term ) {
console.log("running search on ", search_term);
table.search( search_term ).draw();
},
2500
);
if (search_term.length > 3 || search_term.length === 0) {
search(search_term);
}
However, this didn't solve the problem because I would still run into the issue of the input lag after the first draw() gets called after 2.5 seconds.
Short of having the table draw after the entire input has been typed, is there a workaround so that the user input does not lag due to the table having to re-draw?