In the UI5 framework, we do differ how we want to setup the count requests, when an OData service gets called. The mode how this count should be sent and retrieven, can be set in the manifest.json file.
"models": {
// ...
"": {
"type": "sap.ui.model.odata.v2.ODataModel",
"settings": {
"defaultOperationMode": "Server",
"defaultBindingMode": "OneWay",
"defaultCountMode": "InlineRepeat", // <-- Can be set here
"useBatch": true
},
"dataSource": "...",
"preload": true
},
// ...
}
Therefore we can set the following options:
Count mode | Description |
Inline | Count is retrieved by adding $inlinecount=allpages to data requests as long as no count has been determined yet. |
InlineRepeat | Count is retrieved by adding $inlinecount=allpages to every data request. |
Request | A separate $count request will be sent to the OData service. |
None | No info about the count should be sent by the backend. |
The differences are now be shown below within a batch request:
Inline & InlineRepeat
Request
--batch_c433-cbe5-be7d
Content-Type: application/http
Content-Transfer-Encoding: binary
GET AnySet?$skip=0&$top=100&$inlinecount=allpages HTTP/1.1
sap-cancel-on-close: true
sap-contextid-accept: header
Accept: application/json
Accept-Language: de-CH
DataServiceVersion: 2.0
MaxDataServiceVersion: 2.0
--batch_c433-cbe5-be7d--
Response
--767F4D3B41568C8580C8851C34925D590
Content-Type: application/http
Content-Length: 4180
content-transfer-encoding: binary
HTTP/1.1 200 OK
Content-Type: application/json
Content-Length: 3988
dataserviceversion: 2.0
sap-metadata-last-modified: Thu, 07 Dec 2023 13:09:46 GMT
cache-control: no-store, no-cache
{"d":{"__count":"10","results":[ /* ..... */ ]}}
--767F4D3B41568C8580C8851C34925D590--
Request
In this request, you can see that we have to requests. The first one is the $count request, the second the real data request, with the data that can be viewed.
Request
--batch_be18-a9fe-712c
Content-Type: application/http
Content-Transfer-Encoding: binary
GET AnySet/$count HTTP/1.1
sap-cancel-on-close: true
sap-contextid-accept: header
Accept: text/plain, */*;q=0.5
Accept-Language: de-CH
DataServiceVersion: 2.0
MaxDataServiceVersion: 2.0
--batch_be18-a9fe-712c
Content-Type: application/http
Content-Transfer-Encoding: binary
GET AnySet?$skip=0&$top=100 HTTP/1.1
sap-cancel-on-close: true
sap-contextid-accept: header
Accept: application/json
Accept-Language: de-CH
DataServiceVersion: 2.0
MaxDataServiceVersion: 2.0
--batch_be18-a9fe-712c--
Response
--3849B0FB00EBDAAD2D42EA014B3CD2140
Content-Type: application/http
Content-Length: 91
content-transfer-encoding: binary
HTTP/1.1 200 OK
Content-Type: text/plain
Content-Length: 2
dataserviceversion: 2.0
10
--3849B0FB00EBDAAD2D42EA014B3CD2140
Content-Type: application/http
Content-Length: 4180
content-transfer-encoding: binary
HTTP/1.1 200 OK
Content-Type: application/json
Content-Length: 3988
dataserviceversion: 2.0
sap-metadata-last-modified: Thu, 07 Dec 2023 13:09:46 GMT
cache-control: no-store, no-cache
{"d":{"__count":"10","results":[ /* ..... */ ]}}
--3849B0FB00EBDAAD2D42EA014B3CD2140--
None
With none, the same happens as the Inline mode in my case. Therefore the count is always calculated, just the delivery format changes depending on the setting.
Relative links
Leave a Reply