DatatablesBundle icon indicating copy to clipboard operation
DatatablesBundle copied to clipboard

Url in Select2Filter with parameter

Open RLNat opened this issue 5 years ago • 2 comments

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%',
        ))
    ;
}`

RLNat avatar Dec 12 '18 11:12 RLNat

This isn't possible right now, but it really should be.

stephanvierkant avatar Aug 05 '19 13:08 stephanvierkant

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?

poulou0 avatar Oct 01 '20 11:10 poulou0