batch paging

Apr 12, 2011 at 5:16 PM
In the example below how/where do I specify $skip and $top parameters?
OData.request( {
    requestUri: "http://ODataServer/FavoriteMovies.svc/$batch",
    method: "POST",
    data: { __batchRequests: [
       { requestUri: "BestMovies(0)", method: "GET" },
       { requestUri: "BestMovies(1)", method: "GET" }
    ]}
},
function (data, response) {
    //success handler
}, undefined, OData.batchHandler);

Apr 13, 2011 at 7:31 AM

$top and $skip are used on a per-request operation, so if you are making multiple requests in a batched requests, these would go inside the requestUris inside the __batchRequests array, rather than on the top-level one.

Now, in this particular example, BestMovies(0) and BestMovies(1) seem to refer to single entries rather than feeds, so the $top and $skip options don't really make much sense.

A scenario where this might come in handy is if you want to display just the first few items from multiple lists. Let's say for example that you have a feed for "Reviews" and "Products", and you wanted to show on your front page a few of the latest products added and the latest reviews that users made (whether on those products or any other). You can get the "latest" of each from by doing something of the sort, assuming that they both have a "CreatedDate" property.

OData.request( {
    requestUri: "http://ODataServer/MyData.svc/$batch",
    method: "POST",
    data: { __batchRequests: [
       { requestUri: "Reviews?$top=4&$orderby=CreatedDate%20desc", method: "GET" },
       { requestUri: "Products?$top=4&$orderby=CreatedDate%20desc", method: "GET" }
    ]}
},
function (data, response) {
    //success handler
}, undefined, OData.batchHandler);

Please let me know whether this helps,

Marcelo