Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OData pagination with WebApi ( $inlinecount )

I am using OData to paginate a long list of items returned from a web api call. I can filter the data via the url with the start and end index.

The question I have is, how do I know the total number of items? So I can display Page 1 of 3 (20 items) on my mobile device which calls the web api.

like image 640
amateur Avatar asked May 22 '12 16:05

amateur


2 Answers

Try this approach: http://www.strathweb.com/2012/08/supporting-odata-inlinecount-with-the-new-web-api-odata-preview-package/

It uses the latest Web API OData package.

Until the finalized Web API OData package is shipped (sometime this fall, should be around in November), when the $inlinecount is supported out of the box, this solution is likely the best bet.

like image 148
Filip W Avatar answered Sep 27 '22 23:09

Filip W


You can use $inlinecount=allpages in the query to get the count of all the entities in the results without the top and skip. For example:

http://services.odata.org/OData/OData.svc/Products?$top=1&skip=1&$inlinecount=allpages

Returns a single product but also inline count of 9 (since there are 9 products in the entity set).

like image 23
Vitek Karas MSFT Avatar answered Sep 27 '22 23:09

Vitek Karas MSFT