I am currently building a small webpage, which includes a datatable with currently around 10.000 entries. My problem is that populating the datatable blocks the main thread for a few seconds, which results in the webpage being unresponsive for quite some time. Is there any way to fix this behavior by maybe asynchronously populating the datatable?
Initialization works like this:
$(document).ready(function () {
// load all kinds of other charts/data
// ...
loadDataTable();
});
function loadDataTable(){
$.ajax({
type: "GET",
url: /* url to make an API call to the node backend */,
dataType: "json",
success: function(response) {
initDataTable(response)
}
});
}
function initDataTable(data){
$(/*id of the data table*/). DataTable({
sScrollX: "100%",
data: data.data,
columns: [
{ data: /* data selection */ },
{ data: /* data selection */ },
{ data: /* data selection */ },
{ data: /* data selection */ },
{ data: /* data selection */ }
]
});
}
Full source code: https://github.com/fbaierl/bundeszirkus-server/blob/master/public/index.html
Edit: This link provided the correct solution for me: https://datatables.net/examples/server_side/simple.html (thanks Valentin Silvestre)