Skip to content
David Lidström edited this page Oct 27, 2017 · 3 revisions

Home » Paging

Paging with CAML queries is an interesting creature. It's a bit strange.

You can specify a row limit, but you can not specify which row index to start from. Normall you'd want to do like this:

Page 1: Get Row 0-10
Page 2: Get Row 11-20
...

But here you must use the ID of the items to do paging:

Page 1: Get first 10 rows (save: X = ID of the last item)
Page 2: Get first 10 rows (from id: X)

In the exec callback you will get pagingInfo as the third parameter. This will contain a nextPage and prevPage property.

The value of these properties can be pass into the pagingInfo property of exec.


var sql = "SELECT * FROM [TheList] ORDER BY Title LIMIT 50",
    nextPage, prevPage;

function handleResult(err, rows, paging) {
 // Here you can save the paging.nextPage info and use it in the next page's query:
 nextPage = paging.nextPage
 prevPage = paging.prevPage;
}

// First query
camlsql.prepare(sql).exec(handleResult);

// When going to next page, pass the saved value as pagingInfo parameter when invoking exec.
// The nextPage will be null if there is no next page

camlsql.prepare(sql)
   .exec({
     pagingInfo : nextPage
   }, handleResult);

Thanks to https://social.technet.microsoft.com/wiki/contents/articles/18606.sharepoint-2013-paging-with-sharepoint-client-object-model.aspx for clearing this up for me!

Clone this wiki locally