Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
SP.ListItemCollectionPosition Class
Collapse the table of content
Expand the table of content

SP.ListItemCollectionPosition Class

SharePoint 2010

Last modified: June 24, 2010

Applies to: SharePoint Foundation 2010

Specifies the information required to get the next page of data for a list view.

SP.ListItemCollectionPosition

The following example creates an input button on an application page that displays titles from the list of announcements on the current web site two at a time.

<asp:Content ID="Main" ContentPlaceHolderID="PlaceHolderMain" runat="server">
<script type="text/ecmascript" language="ecmascript">

var listItems;                   // The list of retrieved items.
var query;                       // For paging, reuse the same query object.
var targetList;                  // The list from which to retrieve items.
var clientContext;

function runCode() {
  clientContext = new SP.ClientContext();
  targetList = clientContext.get_web().get_lists().getByTitle('Announcements');
  query = new SP.CamlQuery();
  query.set_viewXml("<View><ViewFields><FieldRef Name='Title'/></ViewFields><RowLimit>2</RowLimit></View>");
  listItems = targetList.getItems(query);
  clientContext.load(listItems); 
  clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));
}

function onQuerySucceeded() {
  var message = "Titles, two at a time:\n";
  var listEnumerator = listItems.getEnumerator();
  while (listEnumerator.moveNext())  {
    message += "\nTitle=" + listEnumerator.get_current().get_item("Title")
  }
  alert(message);
  var position = listItems.get_listItemCollectionPosition();
  if (position != null) {
    query.set_listItemCollectionPosition(position);
    listItems = targetList.getItems(query);
    clientContext.load(listItems);  
    clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));
  }
  
}

function onQueryFailed(sender, args) {
  alert('Request failed. \nError: ' + args.get_message() + '\nStackTrace: ' + args.get_stackTrace());
}
</script>

    <input id="Button1" type="button" value="Run Code" onclick="runCode()" />

</asp:Content>
Show:
© 2015 Microsoft