我目前正在构建一个小的网页,其中包括一个数据表,目前大约有10.000条条目。我的问题是填充datatable会阻塞主线程几秒钟,这会导致网页在相当长一段时间内没有响应。是否有任何方法通过异步填充datatable来修复此行为?
初始化工作如下:
$(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 */ }
]
});
}完整源代码:https://github.com/fbaierl/bundeszirkus-server/blob/master/public/index.html
编辑:这个链接为我提供了正确的解决方案:side/simple.html (谢谢Valentin )
发布于 2018-07-10 14:29:17
https://stackoverflow.com/questions/51267678
复制相似问题