Dismiss Notice

Register now to be one of the first members of this SharePoint Community! Click here it just takes seconds!

Dismiss Notice
Welcome Guest from Country Flag

Paging in REST

Discussion in 'Official Microsoft News' started by Brittany Rutherford, Dec 17, 2015.

Thread Status:
Not open for further replies.
  1. Brittany Rutherford

    Brittany Rutherford Guest

    Blog Posts:
    0
    0
    0
    0
    I am trying to implement paging in REST, below is my main main function:


    var _lim = Utilities.ListItemManager("Announcements");

    function _readListItemsPaged() {
    var dfd = $.Deferred();
    var itemsPromise = _lim.readAllItems(3); //passing the number of items per page
    itemsPromise.then(
    function (data, status, jqXHR) {
    _onReadItemsPagedSucceed(data);
    dfd.resolve();
    },
    function (jqXHR, status, error) {
    Utilities.LogResult(error);
    dfd.reject();
    });

    return dfd.promise();
    }

    the _lim looks like this, with the readAllItems

    Utilities.ListItemManager = function (listName){

    var initialSize = 0;

    var skip;

    function _readAllItems(pageSize) {
    var baseUrl = SP.Utilities.UrlBuilder.urlCombine(_spPageContextInfo.webServerRelativeUrl, "_api/web/lists/getByTitle('" + listName + "')/items");
    skip = initialSize * pageSize;
    baseUrl = encodeURI(baseUrl) + "?$skiptoken=Paged%3dTRUEp_ID%3d" + skip + "&$top=" + pageSize;
    initialSize++;
    var dfd = $.ajax({
    url: baseUrl,
    type: "GET",
    contentType: "application/json;odata=verbose",
    headers: {
    "accept": "application/json;odata=verbose"
    }
    });
    return dfd;
    }
    var publicMembers = {
    readAllItems: _readAllItems
    }

    return publicMembers;
    }

    But when I click the button that calls the _lim.readAllItems(3), everytime the initialSize becomes 0 again.

    Continue reading...
     
Thread Status:
Not open for further replies.

Share This Page

LiveZilla Live Chat Software