cancel
Showing results for 
Search instead for 
Did you mean: 

how to get the count property from the oData response

ashish_bansal
Explorer
0 Kudos
3,024

Hi,

I have a fullscreen view in my Fiori app where we call a oData service through table.bindItems() inside the controller.

The binding of items works fine but we have a situation when we need to display the total number of items (for e.g. 515) on the UI. We do not get this information from the VDM, so we plan to use the length property of the getList() method to determine the total number of items. But because of growing feature of the table it only reads 100 items at a time and the length property returns only 100. I have attached the listener attachRequestCompleted() for the model so that once the bindItems() request is complete i can get the length property. But my problem is that i want the total count.

I saw in the debug that when this table.bindItems() gets called it makes a oData service call and in the response i can see that there is a count property available which has the total number of items (515 for my e.g.) but how do i read this count property from the response inside my controller (probably inside my attachRequestCompleted)?? I would really appreciate any help in this regard. Thanks.

Kind Regards,

Ashish

Tags edited by: Michael Appleby

View Entire Topic
0 Kudos

Hi,

Set default count mode of Odata Model as Inline.

var sUrl = "gateway/url";

var model = new sap.ui.model.odata.v2.ODataModel(sUrl, true);

model.setDefaultCountMode("Inline");

If the count mode is Inline, then odata will give the results in the below format.

d: {

results:[{},{}],

__count: "1000"

}

__count will be having total records.

Note: Make sure that $count is implemented in the service.

We can retrieve this results in the afterDataRecevied method.

Thanks,

Bhavya