Don't miss out Virtual Happy Hour this Friday (April 26).

Try our conversational search powered by Generative AI!

Comments Pagination Incorrect

Vote:
 

If I have a criteria of:

            var criteria = new CompositeCriteria<CommentFilter, CommentsExtensionModel>
                           {
                               Filter = new CommentFilter { Ancestor = ancestralComment },
                               PageInfo = new PageInfo { PageSize = 2, PageOffset = 0, CalculateTotalCount = true},
                               OrderBy = { new SortInfo(CommentSortFields.Created, true) }
                           };

Call the service:

var results = _commentService.Get(criteria)

It works, no issues, 2 Results, Total Matching 5.

And as an example lets say it returns

results.Results[0].Data.Id = 123

results.Results[1].Data.Id = 456

All fine.

Now if I paginate:

            var criteria = new CompositeCriteria<CommentFilter, CommentsExtensionModel>
                           {
                               Filter = new CommentFilter { Ancestor = ancestralComment },
                               PageInfo = new PageInfo { PageSize = 2, PageOffset = 1, CalculateTotalCount = true},
                               OrderBy = { new SortInfo(CommentSortFields.Created, true) }
                           };

Again I get 2 more results, but the issue I am seeing is that:

results.Results[0].Data.Id = 456

results.Results[1].Data.Id = 789

As you can see the results returned after the pagination includes the last previous result.

Is this by design or is this a bug?

Thanks

#227538
Sep 07, 2020 12:40
Vote:
 

Hi Jacob -- thanks for the descriptive question. This is by design. I suspect the confusion can be attributed to ambiguous naming of the property PageOffset, which could be interpreted as an index of pages rather than an index to begin the page.

The offset is a zero-based index indicating the point in the result set from which to begin returning results.

So, in your first query (Size = 2, Offset = 0), you would receive:

123 456 789 101112 131415
0 1 2 3 4

Your second query (Size = 2, Offset = 1), delivers:

123 456 789 101112 131415
0 1 2 3 4

To paginate in the manner that I imagine you're expecting, you'll want to add the page size to the previous offset to get the new one.

Size = 2, Offset = 0 (2 results)

123 456 789 101112 131415
0 1 2 3 4

Size = 2, Offset = 2 (2 results)

123 456 789 101112 131415
0 1 2 3 4

Size = 2, Offset = 4 (1 result)

123 456 789 101112 131415
0 1 2 3 4

Hope this helps!

#227591
Edited, Sep 08, 2020 11:35
Vote:
 

Hi Chris,

Thanks for taking the time to look at my query.

The information supplied is helpful and provides insight into pagination. Definintly some confusion around PageOffset!

Thanks again

#227737
Sep 11, 2020 7:13
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.