I noticed some discrepancies in the number of results when getting paged list items when I $orderBy different fields.

I set up a test list with 196 items, the below snippet will get items in batches of 50 and when all done will log the total number of items returned.

If I $orderBy : Id or completely omit $orderBy, I get the correct overall item count (196).

If I $orderBy : Group, the overall item count will be 144. (In this case, the Group column contains non-unique values, if the Group column contained unique values, it would get the correct count, 196) The API generated __next looks OK, but clearly something is going wrong with the paging logic.

Any suggestions? Am I right to just pass __next to the next request, without the original params? They seems to be already included in __next.

(function () {

    var url = '../_api/web/lists/getByTitle(\'Test\')/items',
        getItemsDfd = $.Deferred(),
        params = {
            '$select': 'Title',
            '$orderBy': 'Id', // ok
            //'$orderBy': 'Group', // bad
            '$top': 50
        count = 0;

    function getItems(url, params) {

            url: url,
            type: 'GET',
            data: params,
            headers: {
                'accept': 'application/json;odata=verbose'
            success: function (data) {

                console.log('Url requested', decodeURIComponent(this.url));

                count += data.d.results.length;
                if (data.d.__next) {
                    // for the next batch, use the
                    // url the api returns
                } else {
                    // when __next is undefined
                    // we have reached the end



    // kick off batch operation
    getItems(url, params);

    getItemsDfd.done(function (count) {
        console.log('Item count', count);

  • 1
    Also happening here. The results returned from ODATA query is not the same as when you apply same settings to list view (i.e. ordering with paging, the second page results are different from ODATA's). Did you ever find an answer to this? – Paiman Samadian Nov 2 '16 at 4:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.