Skip to content
This repository has been archived by the owner on Feb 4, 2023. It is now read-only.

Url in Select2Filter with parameter #855

Open
RLNat opened this issue Dec 12, 2018 · 2 comments
Open

Url in Select2Filter with parameter #855

RLNat opened this issue Dec 12, 2018 · 2 comments
Labels

Comments

@RLNat
Copy link

RLNat commented Dec 12, 2018

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%',
        ))
    ;
}`
@stephanvierkant
Copy link
Collaborator

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

@poulou0
Copy link

poulou0 commented Oct 1, 2020

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?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants