1

I'm trying create client-side pagination using Sharepoint Rest Api, i use $skip and $top parameters:

http://siteurl/_api/lists/getByTitle(list name)/items?$skip=0&$top=2 

But with:

http://siteurl/_api/lists/getByTitle(list name)/items?$skip=2&$top=2 

I have the same result as a first link

I know about __next url in response, but i need back and forwerd pagination between pages

Does anyone have usecases for solving this problem?

1 Answer 1

4

Currently $skip query option is not supported in SharePoint 2013/Online.

According to Use OData query operations in SharePoint REST requests:

The $skip query option does not work with queries for SharePoint list items.

There are several options for implementing client-side pagination using SharePoint REST Interface.

Option 1

Utilize $skiptoken query option to return paged results

Format: $skiptoken=Paged=TRUE&p_ID=<last item id to skip>&$top=<items count>

Example

The example demonstrates how to retrieve the limited count of items (2 items) with id equals or greater to 2 from Pages library:

function getPagedItems(webUrl,listTitle,startItemId,itemsCount) { var endpointUrl = webUrl + "/_api/web/lists/getbytitle('" + listTitle + "')/items?$skiptoken=" + encodeURIComponent('Paged=TRUE&p_SortBehavior=0&p_ID=' + (startItemId-1) + '&$top=' + itemsCount); return executeRequest(endpointUrl,'GET'); } getPagedItems('https://contoso.sharepoint.com/','Pages',2,2) .done(function(data){ if(data.d.results.length == 0){ console.log('Items not found'); return; } for(var i = 0; i < data.d.results.length; i++){ var item = data.d.results[i]; console.log(item.Title); } }); 

where

function executeRequest(url,method,headers,payload) { if (typeof headers == 'undefined'){ headers = {}; } headers["Accept"] = "application/json;odata=verbose"; if(method == "POST") { headers["X-RequestDigest"] = $("#__REQUESTDIGEST").val(); } var ajaxOptions = { url: url, type: method, contentType: "application/json;odata=verbose", headers: headers }; if(method == "POST") { ajaxOptions.data = JSON.stringify(payload); } return $.ajax(ajaxOptions); } 

Option 2

Utilize SharePoint 2010 REST interface to retrieve paged results using $skip query option:

Endpoint example: https://contoso.sharepoint.com/_vti_bin/ListData.svc/Pages?$skip=2&$top=2

Sign up to request clarification or add additional context in comments.

3 Comments

i am using same request url but i am getting probelm when like here you r getting 2 data and skip 2 data if in list have 3 data then when call again it skip first 2 item and give 3rd item but it also give me first item also.
Is there anyway to get the all the data without having pagination?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.