Jump to:

3377 Posts in 1001 Topics by 714 members

Data Model Questions

SilverStripe Forums » Data Model Questions » [Solved] Having a problem with Pagination on Silverstripe 3

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1
Go to End
Author Topic: 385 Views
  • neilcreagh
    Avatar
    Community Member
    88 Posts

    [Solved] Having a problem with Pagination on Silverstripe 3 Link to this post

    Hi, I'm using PaginatedList on one of my functions, and it's working fine - limiting the display of the results - but when I try to view the "NextLink" it just displays the same list again (starting with the first result). The URL changes eg. ?start=12 is added but the results don't change.

    Am I missing something?

    My Function (working):

    public function PaginatedWork() {
    $paginatedList = new PaginatedList(DataObject::get("WorkPage", "", "", "", ""));
    $paginatedList->setPageLength(12);
    return $paginatedList;
    }

    On the template <% loop $PaginatedWork %> is working (showing just the first 12 results)

    But the link to view the next Page isn't working:

    <% if $PaginatedWork.NotLastPage %><a class="next" href="$PaginatedWork.NextLink">&gt;</a><% end_if %>

    URL updates with ?start=12 but the items displayed don't change

    Any ideas??

  • ciaranhickey
    Avatar
    Community Member
    17 Posts

    Re: [Solved] Having a problem with Pagination on Silverstripe 3 Link to this post

    I'm not familiar with the new PaginatedList approach - I've only done it the old way but from looking through the docs it looks like you may need to add $this->request as the second argument....

    $paginatedList = new PaginatedList(DataObject::get("WorkPage", "", "", "", ""), $this->request);

    It would need to know which page your are on based on the start parameter (?start=12 ?start=24 etc) - otherwise it's just getting everything from the first db record.

    Hope that helps/works!

  • neilcreagh
    Avatar
    Community Member
    88 Posts

    Re: [Solved] Having a problem with Pagination on Silverstripe 3 Link to this post

    Perfect! That works, thank you!

    385 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.