当启用服务器端处理 ( 'serverSide': true
) 时,实际上 1.9.x 函数fnGetData()和 1.10.x 函数data()都只返回当前页面的数据。
此行为可以通过查看服务器端处理示例并在控制台$('#example').dataTable().fnGetData()
或$('#example').DataTable().data()
.
为了检索所有数据,您需要发出一个单独的 AJAX 请求来模仿 DataTables 的行为。
由于您的问题已被标记datatables-1.10
,我假设您使用的是 DataTables 1.10.x。您可以使用ajax.params(),它获取 DataTables 在最后一个 Ajax 请求中提交给服务器的数据。
function processAllRecords(){
var req = $('#example1 table').DataTable().ajax.params();
// Reset request parameters to retrieve all records
req.start = 0;
req.length = -1;
req.search.value = "";
// Request data
$.ajax({
'url': 'script.php',
'data': req,
'dataType': 'json'
})
.done(function(json){
// json.data is array of data source objects (array/object),
// one for each row
console.log(json);
});
}