How to paging with caml query

I have 10 items with ID from 1 to 10 and set order by on Created field Ascending='FALSE'Row Limit is 3. I use SPListItemCollectionPosition for pagination to limit the number of returned items. First query, I get only 3 items, namely 10, 9 and 8 in order. Second, I need to get expected items, namely 7, 6 and 5, but I get incorrect results.

I have read some articles that tell me to use the syntax, that I pass ID of the first second results set and its value of sort field, Created field, like:

Paged=TRUE&p_FSObjType=0&PagedPrev=TRUE&p_Created=20150818 07:02:48&p_ID=7

However, the query returns items with id 4, 3 and 2?

I also use the syntax "Paged=TRUE&PagedPrev=TRUE&p_Created={0}&p_ID={1}" but the result is still wrong. As far as I understand here is that the query gets items, start from the first item on the list (ID=1) and get only three items, which is set by row limit, and then sort them by Created field.

Some tell me that I could capture the first and the last item of the results etc, but in my case, I only have one way backward.

Please give me advice. What is the correct syntax should I use?

Thanks

August 19th, 2015 12:36am

Hi, 

AFAIK, Paging with order by in your case is CAML query limitation. You are getting incorrect results due to paging with order by. For the first page you will get correct result but from second page when you get position of last element of previous page, it will take it as ID. And from next page it will start taking elements from ID+1. 

You can get all elements and perform CSOM operations for sorting and binding to grid using javascript.

August 19th, 2015 2:13am

@RajendraPratap: I have had a look at those posts but I does not work in my case

@Eno: thanks, it seems to be a limitation.

Free Windows Admin Tool Kit Click here and download it now
August 19th, 2015 2:55am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics