Tabulator 5.0 中的远程分页错误
Error with Remote Pagination in Tabulator 5.0
我的制表符 5.0 table 工作正常。但是当我尝试使用远程分页时,它根本不再起作用。
var table = new Tabulator("#account-tran-detail-table", {
pagination:true,
paginationMode:"remote", //if this line is commented out then it works fine without pagination
paginationSize: 12,
dataSendParams:{
page: "page",
size: "page_size",
},
dataReceiveParams:{
last_page:"total_pages",
} ,
ajaxResponse:function(url, params, response){
return response.results; // return the array of table items
},
});
table.on("tableBuilt", function(){
table.setColumns(columns);
});
function generateReport () {
table.clearData();
var columns = [
{title:"id", field:"id", headerFilter:false, visible:false, download:true},
{title:"name", field:"name", headerFilter:false, visible:false, download:true},
];
var gender = "m";
var url = "/api/v1/myendpointname/";
var append_params = "?gender=" + gender;
$("#tableBuilt").destroy;
table.setData(url + append_params);
};
响应如下所示:
{
"count": 10,
"total_pages": 3,
"next": "http://localhost:8000/myendpointname/?gender=m&page=2&size=3
"previous": null,
"results": [
{
"id": 1,
"gender": "m",
"name": "abc",
},
{
"id": 2,
"gender": "m",
"name": "def",
},
{
"id": 3,
"gender": "m",
"name": "ghi",
},
]
}
您可以看到我在哪里要求制表符读取 total_pages
而不是使用 dataReceiveParams
默认的 last_page
。您还可以看到我要求制表符发送 page_size
而不是默认 size
的位置,方法是使用 dataSendParams
生成请求。
我收到两个警告。 . .
Remote Pagination Error - Server response missing 'undefined' property Page.js:707:11
Remote Pagination Error - Server response missing 'undefined' property Page.js:754:11
后面出现错误。
Data Loading Error - Unable to process data due to invalid data type
Expecting: array
Received: undefined
Data: undefined
警告引用的代码:
707: console.warn("Remote Pagination Error - Server response missing '" + this.dataReceivedNames.last_page + "' property");
754: console.warn("Remote Pagination Error - Server response missing '" + this.dataReceivedNames.data + "' property");
所以在我看来制表符并没有“看到”响应的 total_pages
部分。为什么不使用 defaultReceiveParams
?会不会是因为我的 ajaxResponse
函数 returns response.results
并去掉了其余的响应?
(Chrome 和 Firefox 的行为相同)
使用ajaxResponse
到return数据和last_page作为
我的制表符 5.0 table 工作正常。但是当我尝试使用远程分页时,它根本不再起作用。
var table = new Tabulator("#account-tran-detail-table", {
pagination:true,
paginationMode:"remote", //if this line is commented out then it works fine without pagination
paginationSize: 12,
dataSendParams:{
page: "page",
size: "page_size",
},
dataReceiveParams:{
last_page:"total_pages",
} ,
ajaxResponse:function(url, params, response){
return response.results; // return the array of table items
},
});
table.on("tableBuilt", function(){
table.setColumns(columns);
});
function generateReport () {
table.clearData();
var columns = [
{title:"id", field:"id", headerFilter:false, visible:false, download:true},
{title:"name", field:"name", headerFilter:false, visible:false, download:true},
];
var gender = "m";
var url = "/api/v1/myendpointname/";
var append_params = "?gender=" + gender;
$("#tableBuilt").destroy;
table.setData(url + append_params);
};
响应如下所示:
{
"count": 10,
"total_pages": 3,
"next": "http://localhost:8000/myendpointname/?gender=m&page=2&size=3
"previous": null,
"results": [
{
"id": 1,
"gender": "m",
"name": "abc",
},
{
"id": 2,
"gender": "m",
"name": "def",
},
{
"id": 3,
"gender": "m",
"name": "ghi",
},
]
}
您可以看到我在哪里要求制表符读取 total_pages
而不是使用 dataReceiveParams
默认的 last_page
。您还可以看到我要求制表符发送 page_size
而不是默认 size
的位置,方法是使用 dataSendParams
生成请求。
我收到两个警告。 . .
Remote Pagination Error - Server response missing 'undefined' property Page.js:707:11
Remote Pagination Error - Server response missing 'undefined' property Page.js:754:11
后面出现错误。
Data Loading Error - Unable to process data due to invalid data type
Expecting: array
Received: undefined
Data: undefined
警告引用的代码:
707: console.warn("Remote Pagination Error - Server response missing '" + this.dataReceivedNames.last_page + "' property");
754: console.warn("Remote Pagination Error - Server response missing '" + this.dataReceivedNames.data + "' property");
所以在我看来制表符并没有“看到”响应的 total_pages
部分。为什么不使用 defaultReceiveParams
?会不会是因为我的 ajaxResponse
函数 returns response.results
并去掉了其余的响应?
(Chrome 和 Firefox 的行为相同)
使用ajaxResponse
到return数据和last_page作为