DatatablesBundle
DatatablesBundle copied to clipboard
Url in Select2Filter with parameter
Hey!
I have a datatables with places. What I want is to list in the select2Filter only sections in the room. How can I pass the id of the room (section.room.id) in the url (manage_section_list).
Thank you.
Here the PlaceDatatable.php :
`/** * Builds the datatable. * * @param array $options */ public function buildDatatable(array $options = array()) { // TODO: Implement buildDatatable() method. $this->language->set(array( 'cdn_language_by_locale' => true, ));
$this->ajax->set(array());
$this->options->set(array(
'classes' => Style::BOOTSTRAP_3_STYLE . ' table-responsive',
'individual_filtering' => true,
'individual_filtering_position' => 'head',
'order' => array(array(0, 'asc')),
'order_cells_top' => true,
'length_menu' => array(15, 25, 50, 100),
'page_length' => 15,
'paging_type' => Style::FULL_NUMBERS_PAGINATION
));
$this->features->set(array(
'auto_width' => true,
'defer_render' => false,
'info' => true,
'length_change' => true,
'ordering' => true,
'paging' => true,
'processing' => true,
'scroll_x' => false,
'scroll_y' => '',
'searching' => true,
'state_save' => false
));
$this->columnBuilder
->add('id', Column::class, array(
'title' => '',
'searchable' => false,
'orderable' => true,
))
->add('section.name', Column::class, array(
'title' => 'Section',
'width' => '100%',
'filter' => array(Select2Filter::class,
array(
'search_type' => 'eq',
'cancel_button' => true,
'url' => 'manage_section_list',
),
),
))
->add('number', Column::class, array(
'title' => 'Number',
'width' => '100%',
))
->add('section.room.id', Column::class, array(
'title' => 'Room',
'width' => '100%',
))
;
}`
This isn't possible right now, but it really should be.
I think its easy, at least in theory!
If we make a custom twig function to check if the route name exists
and use it in Resources/views/filter/select2.html.twig
line 33
it will work for both route names and generated paths like:
...
->add('name', Column::class, array(
'title' => 'Title',
'searchable' => true,
'orderable' => true,
'filter' => [Select2Filter::class, [
'url' => $this->router->generate('some_route', ['id' => $options['entity_id']]),
...
Should I fork and try or its so easy that its not worth it?