使用帶有伺服器端處理的 ajax 載入資料
var MY_AJAX_ACTION_URL = "path/to/controller.php";
var table = $('#user_list_table').DataTable({
"autoWidth": true,
"paging": true,
"searching": true,
"ordering": true,
"language": {
"zeroRecords": "No data Found",
"processing": 'Loading'
},
"info": false,
"stripeClasses": [ "odd nutzer_tr", "even nutzer_tr"],
"columns": [
{'data':'uid',"visible": false},
{'data':'name','orderable': true},
{'data':'phone','orderable': true},
{'data':'email','orderable': true },
{'data':'address','orderable': true}
],
"order": [[ 1, "desc" ]],
"processing": true,
"serverSide": true,
"ajax":MY_AJAX_ACTION_URL
});
對 MY_AJAX_ACTION_URL
的響應應嚴格遵循以下格式:
{
"draw": 1,
"recordsTotal": 2,
"recordsFiltered": 2,
"data": [
{"name":"XYZ","phone":"678654454","email":"xyz@gmail.com","address":"true"},
{"name":"ABC","phone":"678654455","email":"abc@gmail.com","address":"true"}
]
}
請注意,如果呼叫的輸出與上述格式不匹配,則會導致 table
初始化出錯。