cancel
Showing results for 
Search instead for 
Did you mean: 

[OData] Get $count result in sapui5 controller

sdebeaulieu
Participant
0 Kudos

Hello,

In a Sapui5 application, I would like to display total of an OData EntitySet. I can see in Network calls that $count is retrieved in a $batch call :

Header : GET MyEntitySet/$count

Response : 7163

How can I retrieve this value in the controller? I would like to avoid another call of $count.

Thanks for your help.

Cheers,

Sev

Accepted Solutions (0)

Answers (2)

Answers (2)

maheshpalavalli
Active Contributor

assuming the request went via the binding to the table, you need to register for the update finished event for the table or list and in the event handler method, use the below code. check in the debugging once to make sure the code is fine

oEvent.getParameter("total").

You might also have to check if the items length is final by using the below code.

if( this.getView().byId("List").getBinding("items").isLengthFinal() ){ // because this event will be triggered 2 times as far as i remember

var scount = oEvent.getParameter("total");

}

Best Regards,
Mahesh

sdebeaulieu
Participant
0 Kudos

Thanks for your answer. I was using this method before, but unfortunately I don't use a sap.m.Table anymore but a sap.ui.table.Table. This component doesn't have updatefinished event.

Any other way to get total value?

Best regards,

Sev

maheshpalavalli
Active Contributor

Try to attach a event handler for the event: requestCompleted of odata v2 model. you might get the response over there.

Best Regards,
Mahesh

sdebeaulieu
Participant
0 Kudos

Perfect! Thank you.

maheshpalavalli
Active Contributor
0 Kudos

you are most welcome and please mark the question as answered 🙂

Best Regards,
Mahesh