[英]Loading a datatable withouth blocking the main thread
我目前正在建設一個小型的網頁,其中包括一個數據表與目前約為10.000條目。 我的問題是,填充數據表會阻塞主線程幾秒鍾,這會導致網頁在相當長的時間內沒有響應。 有沒有辦法通過異步填充數據表來解決此問題?
初始化工作如下:
$(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
編輯 :此鏈接為我提供了正確的解決方案: https : //datatables.net/examples/server_side/simple.html (感謝Valentin Silvestre)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.