Pagination

Silverstripe Version:4

**Hey there,
I try to get a paginated list of dataobjects, its rendering great with the code below, but the pagination links are not working. What am I missing? I think I need to add the HTTPRequest, but i don’t know how
**

Details of your query go here

use Page; 
use SilverStripe\ORM\PaginatedList;
  
class MyPage extends Page 
{
public function MyList()
    {
    	$list = MyDataObject::get();
        return new PaginatedList($list);
    }   
}

Place MyList function inside MyPageController

That chunk of code should be in your controller not the model

Thank you all, stupid mistake, here is the working code in the page CONTROLLER

use PageController;    
use SilverStripe\ORM\PaginatedList;

class MyPageController extends PageController 
{
public function MyList()
    {
    	$list = MyDataObject::get();
        return new PaginatedList($list, $this->getRequest());
    }   
}
1 Like

Hi,

Yes, it looks like you’re missing the request.

Have a look here for the syntax: How to Create a Paginated List – SilverStripe Documentation

public function PaginatedPages() 
{
    $list = Page::get();
    return new PaginatedList($list, $this->getRequest());
}

thank you! I tried that before, but i get:

[Emergency] Uncaught BadMethodCallException: Object->__call(): the method ‘getRequest’ does not exist on 'xxx\MyPage’

… if i use the code below. what am I missing?

use Page; 
use SilverStripe\ORM\PaginatedList;
  
class MyPage extends Page 
{
public function MyList()
    {
    	$list = MyDataObject::get();
        return new PaginatedList($list, $this->getRequest());
    }   
}

I have a pagination tutorial through which you can easily understand how to do this. @flxbot