omines / datatables-bundle

DataTables bundle for Symfony
https://omines.github.io/datatables-bundle/
MIT License
260 stars 114 forks source link

So, what with column filters ? #347

Open e1sep0 opened 3 months ago

e1sep0 commented 3 months ago

Hi, are you planning to fix column filters? They're not displayed ( Neither Choice filter, nor Text filter:

$statusFilter = new ChoiceFilter();
        $statusFilter->set([
            'choices' => ['foo' => 'bar', 'bar' => 'baz']
        ]);
        $textFilter = new TextFilter();

        $table = $dataTableFactory->create()
            ->add('id', TextColumn::class, ['label' => 'Id'])
            ->add('status', TextColumn::class, ['field' => 'e.status','searchable' => true, 'filter' => $statusFilter])
            ->add('name', TextColumn::class, [ 'field' => 'e.name', 'filter' => $textFilter])
            ->createAdapter(ORMAdapter::class, [
                'entity' => Entity::class,
                'hydrate' => AbstractQuery::HYDRATE_ARRAY,
                'query' => function (QueryBuilder $builder) use ($scheduleIds): void {
                    $builder
                        ->select('e')
                        ->from(Entity::class, 'e')
                    ;
                },
            ])
            ->handleRequest($request);

datatables.yaml:

# Latest documentation available at https://omines.github.io/datatables-bundle/#configuration
datatables:
    language_from_cdn: false
    # Set options, as documented at https://datatables.net/reference/option/
    options:
        lengthMenu : [10, 25, 50, 100, 250, 500, 1000, 2500]
        pageLength: 10
        dom: "<'row' <'col-sm-12' ftr>><'row' <'col-sm-6'l><'col-sm-6 text-right'pi>>"
        searching: true

    template_parameters:
        # Example classes to integrate nicely with Bootstrap 3.x
        className: 'table table-bordered table-hover data-table report-table'
        columnFilter: 'both'

    # You can for example override this to "tables" to keep the translation domains separated nicely
    translation_domain: 'messages'

table.html.twig:

$(function () {
            $('#table').initDataTables({{ datatable_settings(datatable) }},
                {
                    searching: true,
                    dom: 'Bfltip',
                });
        });
curry684 commented 3 months ago

Column filters are essentially "unsupported, use at own risk". People are using them and happy with them but I have no clue how they work as we don't use it ourselves. PRs to improve them welcome.

rostyslav-a-smartgamma commented 1 month ago

Hope this feature will work soon in further updates, I need a multiple choice filter/search... As I see there is no way how to do this with column search.

kathibeepboop commented 3 weeks ago

There is a open pr for this https://github.com/omines/datatables-bundle/pull/348 Alternativly you could use my fork (which is poorly maintainted) and use the column filters https://github.com/omines/datatables-bundle/pull/336#issuecomment-2051441199

Keep in mind that my fork will get some other changes too, like case insensitive global search and stuff