Skip to content
This repository has been archived by the owner on Dec 31, 2019. It is now read-only.

Multiple datatable in the same view

benjaminu edited this page Dec 5, 2012 · 4 revisions

To declare multiple datatables in the same view, you have to set the datatable identifier in you controller with 'setDatatableId': Each of your databale config methods ( _datatable() , _datatable_1() .. _datatable_n() ) needs to set the same identifier used in your view:

**In the controller**
    protected function _datatable() 
    {
        // ...
        return $this->get('datatable')
            ->setDatatableId(dta-unique-id_1')
            ->setEntity('XXXMyBundle:Entity', 'x')
        // ...
    }
    
    protected function _datatableSecond() 
    {
        // ...
        return $this->get('datatable')
            ->setDatatableId(dta-unique-id_2')
            ->setEntity('YYYMyBundle:Entity', 'y')
        // ...
    }

**In the view**
    {{ 
        datatable({ 
            'id' : 'dta-unique-id_1',
            ...
            'js' : {
                'sAjaxSource' : path('RouteForYour_grid_action_1')
            }
        }) | raw
    }}
    
    {{ 
        datatable({ 
            'id' : 'dta-unique-id_2',
            ...
            'js' : {
                'sAjaxSource' : path('RouteForYour_grid_action_2')
            }
        }) | raw
    }}