Monday 27 August 2012

Paging in SharePoint JavaScript Client Object Model

Paging can be of great help when you want to improve the performance of your code especially when you are working on front-end development and want to reduce the page response time. Let us see how can be implement paging when working with the JavaScript Client Object Model.

The important parts to note in this code are the RowLimit element in the CAML query and the SP.ListItemCollection.get_listItemCollectionPosition(); property. Please have a look at the comments to know more details about the individual lines of code.

The ListItemCollectionPosition.pagingInfo determines the id of the last item fetched along with the filter and sorting criteria. It specifies information, as name-value pairs, required to get the next page of data for a list view.


Nvikey said...

Hi Vardhaman,

This is fine to navigate to next page. I can use the id of the last item queried. But when we want to go to previous page, what can be the solution.. we cannot the use this method, to navigate both sides.. it is helpful only for navigating to next page..

Vardhaman Deshpande said...

Hi Vignesh

To go to the previous page, you will have to keep track of the listitemcollectionposition of the previous page in a variable. And when you want to go to the specific position, use the value from the variable.

Alternatively, you can cache the current list items when you go to the next page. And when you want to go back from the next page, show the cached items