cnizzardini / cakephp-datatable

CakePHP Component for interoperability between CakePHP 2.x and jQuery DataTables plugin.
62 stars 47 forks source link

Paginate different model from controller #6

Closed walliby closed 11 years ago

walliby commented 11 years ago

Great component! However, I am having trouble paginating another model from within my controller. The models are related but I want to paginate this other model independently. I am using the following code in my UserProspects controller which typically works but not with this component. Any advice would be greatly appreciated. Thanks!

$this->Paginator->settings = array( 'Person' => array('fields' => array('Person.id', 'Person.name', 'Person.class'))); $this->Paginator->paginate('Person');

cnizzardini commented 11 years ago

Something like this should work:

$this->paginate = array( 'fields' => array('Person.id', 'Person.name', 'Person.class') ); $this->set('response', $this->DataTable->getResponse($this, $this->Person)); $this->set('_serialize', 'response');

Note this example assumes your controller $uses Person P.s. this is covered in the readme doc

walliby commented 11 years ago

That did the trick, thanks!