tigrang / cakephp-datatable

JQuery DataTable plugin server-side processing component for CakePHP
47 stars 29 forks source link

What's the right way to paginate an associated model? #27

Closed luisillo26 closed 11 years ago

luisillo26 commented 11 years ago

I'm trying to paginate an associated model inside of a view called view. The issue is: instead I get te JSON data, I'm getting the HTML of the view where I'm trying to render the Child data. Please help me telling me how it has to be done. Thanks in advance.

From my controller I'm calling the paginate method in the Parent controller as follows:

public funtion view(){
    $this->DataTable->settings['columns'] = array(
        'Child.PROVEEDOR' => 'Supplier',
        'Child.DESTINATARIO' => 'Consignee',
        'Child.NUMFACTURA' => 'Invoice number'
    );
    $this->DataTable->paginate = array('Parent', 'Child');
}

and in my view I render the table:

echo $this->DataTable->render('Child');

I also have the app/View/Parent/datatable/view.ctp file as this:

foreach($dtResults as $result) {
    $this->dtResponse['aaData'][] = array(
        $result['Child']['PROVEEDOR'],
        $result['Child']['DESTINATARIO'],
        $result['Child']['NUMFACTURA'],
    );
}
tigrang commented 11 years ago

What error are you getting? Try adding public $uses = array('Parent', 'Child') in your controller. I don't remember how I have that setup.

tigrang commented 11 years ago

Please re-open if you have questions.

mbialasek commented 10 years ago

I my app I have following models: Category ----(has many)---> Subcategory----(has many)--->Product and I need to show Category name on Product list, so I need an information from 2 step higher. I try:

'DataTable.DataTable' => array( 'columns' => array( 'id' => false, 'Subcategory.Category.name' => "Category", 'actions' => null), ),

But is not working