We are trying to implement efficient server-side pagination for an sap.f.GridList. Our goal is to load an initial set of items, and when the user clicks "Load More", fetch the next set from the server and append them to the list.
The Problem:
We are manually fetching the first 5 items from our OData service and populating a JSONModel. The GridList is configured with growing="true" and growingThreshold="5". The list correctly displays the first 5 items.
However, even though our OData service response (__count) confirms that there are more than 5 items in total on the server, the "Load More" button (or trigger) never appears. This prevents us from loading the next page.
What We Have Tried:
We attempted to use the growingStarted event to manually trigger a fetch for the next page, but this doesn't feel right and hasn't worked as expected. The core issue seems to be that the GridList's growing feature doesn't know that more data exists on the server when it's bound to a simple JSONModel.
Is there a way to fix our manual JSONModel implementation?
B) Or, should we switch to a programmatically created ODataModel in the controller? If so, what is the simplest way to configure the GridList binding to handle server-side paging, static filtering, and dynamic search correctly with this model type?
.xml file
<f:GridList
id="gridList"
items="{/results}"
growing="true"
growingThreshold="5"
growingStarted=".onGridUpdateFinished">
controller file
onInit: function () {
this._bIsLoading = false;
this.data = { results: []};
this.loadData(false); // Load initial page
},
loadPageData: function (bAppend) {
var that = this;
if (this._bIsLoading) {
return;
}
var skip = bAppend ? this.data.results.length : 0;
var top = 5;
var query = "&$orderby=ModifiedAt%20desc&$top=" + top + "&$skip=" + skip + "&$inlinecount=allpages&$format=json";
// We use a custom factory to get the OData model and call 'findAll'
var latestDataAndAllCount = ModelFactory.getInstance().getOdataModel("dummy.svc",
"dummypath").findAll({
"where": query
}, {
async: true
});
$.when(pageRequest).done(function (oLatestData) {
if (bAppend) {
that.data.results = that.data.results.concat(oLatestData.d.results);
that.getView().getModel().refresh();
} else {
that.data = oLatestData.d;
var oModel = new JSONModel(that.data);
that.getView().setModel(oModel);
}
});
},
// Our attempt to manually trigger the next fetch
onGridUpdateFinished: function (oEvent) {
var that = this;
var sReason = oEvent.getParameter("reason");
if (sReason === "Growing") {
that._bIsLoading = false;
}
that.loadData(true);
if (sReason === "Change") {
that._bIsLoading = true;
}
}
});
__next(in OData V2) or@odata.nextLink(in V4). But your code snippet with$skipand$topindicates client-side paging (The client controls the number of entities in the request). Does your OData V2 service include__nextin the JSON response?