Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Data Model Questions /

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

PaginatedList


Go to End


2 Posts   1975 Views

Avatar
Dimenicius

Community Member, 8 Posts

9 May 2013 at 6:52am

Edited: 13/05/2013 10:56am

Hi, I'm having some trouble working with PaginatedLists. Posted this on General Question Forum but I think here is the right place.
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 %> 

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 }

Avatar
bepe

Community Member, 4 Posts

17 June 2013 at 3:20am

i fixed this error by putting my Paginando-function into the Controller-Class.

that's also the answer to one of your other threads.

(i found this thread first, so there should be a answer to this question, too.)