'How can I get the count of filtered OData results? [duplicate]
I am attempting to get the count of filtered OData results in a Fiori SAPUI5 application. I am able to get the correct count using both $count
and $inlinecount
in Postman using the following:
MyEntitySet/$count?$filter=Id eq '9'
and
MyEntitySet?$filter=Id eq '9'&$inlinecount=allpages&$format=json
.
However, when I try to use these query parameters in my UI5 code, I don't get the result I want.
myV2ODataModel.read("/MyEntitySet/$count?$filter=Id eq '9'", {/*...*/});
gives me the count of the unfiltered results, while
myV2ODataModel.read("/MyEntitySet?$filter=Id eq '9'&$inlinecount=allpages", {/*...*/});
gives me all the records, and I am unable to access the inline count.
Solution 1:[1]
Check the documented API reference for myV2ODataModel.read
: https://sdk.openui5.org/api/sap.ui.model.odata.v2.ODataModel#methods/read
So it should be:
// Filter required from "sap/ui/model/Filter"
myV2ODataModel.read("/MyEntitySet/$count", {
// ...,
filters: [
new Filter(/*...*/),
],
});
- API reference for
sap/ui/model/Filter
: https://sdk.openui5.org/api/sap.ui.model.Filter - Live Update the Number of Items
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 |