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.

Template Questions /

Can't Get Pagination to Work


Reply


5 Posts   467 Views

Avatar
PattyOK

Community Member, 5 Posts

6 February 2014 at 9:28am

Hello - I attempted to follow this tutorial on pagination. [url]http://doc.silverstripe.org/framework/en/howto/pagination[/url]

I cant make it work the way I want. I dont know if I am doing something wrong or if I am misinterpreting how its supposed to be used...

This is in my page controller - I am limiting this to "Projects".

public function PaginatedProjects() {
$pagination = new PaginatedList(Page::get('Project'), $this->request);
return $pagination;
}

In my Project page template this works to return a list of projects

<% loop $PaginatedProjects %>
         <li><a href="$Link">$Title</a></li>
      <% end_loop %>

but none of the other methods seem to work.
TotalItems always returns 1
PrevLink, NextLink return blank

I really just want Prev, Next links. Is there a working example of pagination out there or a prev/next example that works with SS3?

Avatar
Willr

Forum Moderator, 5513 Posts

6 February 2014 at 4:32pm

That seems correct, do you get a list of all your Projects at least? The example on http://doc.silverstripe.org/framework/en/howto/pagination does also work as reference.

Avatar
ajshort

Community Member, 244 Posts

6 February 2014 at 6:54pm

I suspect that "Page::get('Project')" should probably be Project::get()

Avatar
PattyOK

Community Member, 5 Posts

7 February 2014 at 8:17am

Ack. I grossly misinterpreted what this was going to do for me :). Setting the page length to less than the number of pages, I finally got the controls to show up and now I see what they do... (duh). If the tutorial page had a working example that actually demonstrates the functionality that might have helped me come to that sooner... Anyways thanks for your responses.

Avatar
thomas.paulson

Community Member, 86 Posts

7 February 2014 at 6:22pm

try this

public function PaginatedProjects() {
$pagination = new PaginatedList(Project::get(), $this->request);
return $pagination;
}