【发布时间】:2022-01-02 13:33:56
【问题描述】:
我的制表符 5.0 表工作正常。但是当我尝试使用远程分页时,它根本不起作用。
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",
},
]
}
您可以通过使用“dataReceiveParams”查看我要求制表符在哪里读取“total_pages”而不是默认的“last_page”。您还可以通过使用“dataSendParams”生成请求来查看我要求制表符在哪里发送“page_size”而不是默认的“size”。
我收到两个警告。 . .
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 函数返回了 response.results 并去掉了其余的响应吗?
(Chrome 和 Firefox 的行为相同)
【问题讨论】:
标签: javascript ajax pagination tabulator