I have a jqGrid that points at an external API, which I have no control over. This external API has two endpoints:
Based on user input the jqGrid filter gets converted into the appropriate query-string to filter the external API's Data and Count Endpoints.
I have jqGrids url
being dynamically built based off of user input and targets the Data Endpoint...and during the loadBeforeSend()
event it calls the Count Endpoint to get the latest pagination information based on users filter.
I am using the jsonreader capabilities:
jsonReader: {
root: 'products',
id: 'id',
records: function () {
return gridTotal;
},
total: function () {
// var totalPages = (gridTotal + reqOptions.limit-1) / reqOptions.limit;
var totalPages = Math.ceil(gridTotal / reqOptions.limit);
console.log('totalPages: ' + totalPages);
return totalPages;
},
page: function () {
//var totalPages = Math.ceil(gridTotal/20);
console.log('currentPage: ' + reqOptions.page);
return reqOptions.page;
}
},
Sample of the loadBeforeSend method:
loadBeforeSend: function (xhr, settings) {
settings.url = _newUrl || endpointURL;
// Lets fetch our data count...this may change as items get published so lets fetch during load
products.count(accessToken, _filterQuery)
.success(function (resp) {
// This is the total number of products that match our current search
gridTotal = resp.count;
}).catch(function (err) {
console.error(err);
});
}
Fetching from the Data Endpoint works really well, the issue is how to call the Count Endpoint and update the pagination data.
Tried the following:
setGridParam
for records, last_page, etc.,getGridParam('reccount')
Is there a way to
gridTotal
is setUpdated to show @Oleg solution
loadBeforeSend: function (xhr, settings) {
settings.url = _newUrl || endpointURL;
// Lets fetch our data count...this may change as items get published so lets fetch during load
products.count(accessToken, _filterQuery)
.success(function (resp) {
// This is the total number of products that match our current search
gridTotal = resp.count;
gridTotal = resp.count;
grid.jqGrid('setGridParam', {
page: gridOpts.jsonReader.page(),
records: gridTotal,
lastpage: gridOpts.jsonReader.total()
});
grid[0].updatepager(false, true);
}).catch(function (err) {
console.error(err);
});
}
答案 0 :(得分:2)
我希望我能正确理解你的问题。在这种情况下,您可以先从数据端点加载主数据。然后(在loadComplete
内)您可以手动启动新 $.ajax
请求以从计数端点获取数据并更新内部的分页数据success
的{{1}}回调。
更新寻呼机需要做的是:
$.ajax
,page
和records
参数。lastpage
,它将使用上述选项并刷新寻呼机上的信息。您可以在the old answer中看到$("#grid")[0].updatepager(false, true);
的使用示例。