Jump to:

23493 Posts in 18997 Topics by 2878 members

General Questions

SilverStripe Forums » General Questions » PaginatedList error

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

Page: 1
Go to End
Author Topic: 465 Views
  • Dimenicius
    Avatar
    Community Member
    8 Posts

    PaginatedList error Link to this post

    Hi, I'm having some trouble working with PaginatedLists.
    I want to make my category page show 15 post in a paginatedlist but the pages must go on 5 pages step. (i.e. Page1 results: post 1-15, Page2 results: post 6-20). The first 5 results won't show the same fields of the others.
    The first page is working fine, but the buttons to change pages doesn't work, when I click on it, the URL changes but the page shows the same results.

    Here is my actual code:

    Subcategoria.php

    public function Datalist(integer $num, $start ) {
    $paginatedList = new PaginatedList(Page::get());
    $paginatedList->setPageLength($num)->setPageStart($start)-> where('"ParentID" = 7')->Sort("ID", "Desc");
    return $paginatedList;
    }

    subcategoria.ss

    <% loop $Datalist(5,0) %>
    <a href=$link> $Title </a><br>
    <% end_loop %>

    ---<br><br>

    <% loop $Datalist(10,5) %>
    <a href=$link> $Title </a><br>
    <% end_loop %>

    =Pagination=<br><br>

    <% if $Datalist(5,0).MoreThanOnePage %>
    <% if $Datalist(5,0).NotFirstPage %>
    <a class="prev" href="$Datalist(5,0).PrevLink">Prev</a>
    <% end_if %>
    <% loop $Datalist(5,0).Pages %>
    <% if $CurrentBool %>
    $PageNum
    <% else %>
    <% if $Link %>
    <a href="$Link">$PageNum</a>
    <% else %>
    ...
    <% end_if %>
    <% end_if %>
    <% end_loop %>
    <% if $Datalist(5,0).NotLastPage %>
    <a class="next" href="$Datalist(5,0).NextLink">Next</a>
    <% end_if %>
    <% end_if %>

  • Bambii7
    Avatar
    Community Member
    254 Posts

    Re: PaginatedList error Link to this post

    Hmm pagination is tricky.
    It looks like $Datalist(5,0) is always starting at 0 so never getting anything more than the first 5 results. You need a mechanism to increment the page. The link for forward or back could hook up to a function off the controller which increments an internal number stored in session... but you'd also need a goTo($here) function for the numbered pages.

    Haven't read through it but hopefully this could be of some help http://doc.silverstripe.org/framework/en/howto/pagination

  • Dimenicius
    Avatar
    Community Member
    8 Posts

    Re: PaginatedList error Link to this post

    I've tried to:

       public function Paginando() {
    return new PaginatedList($this->Children(),$this->request);
    }

    just to make it work with the children pages, but whenever i add the "$this->request", the page crash and shows this message:

    26    public function __construct(SS_List $list, $request = array()) {
    27       if (!is_array($request) && !$request instanceof ArrayAccess) {
    28          throw new Exception('The request must be readable as an array.');
    29       }

  • IOTI
    Avatar
    Community Member
    189 Posts

    Re: PaginatedList error Link to this post

    Is your function in the controller class? i.e in the "class Page_Controller extends ContentController"

    465 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.