vedmack / yadcf

Yet Another DataTables Column Filter (yadcf)
http://yadcf-showcase.appspot.com/
MIT License
731 stars 285 forks source link

Text filter not including value with request to server with ajax #679

Closed Kian987 closed 7 months ago

Kian987 commented 7 months ago

Hi,

I am experiencing the same exact problem described here on Stackoverflow. I am using 0.9.3 but the issue occurs also with 0.9.4.beta.46.

The issue is that filter_type text and auto_complete do not send any value to the server although the request fires and reaches the server. More precisely I am also using multi_select, range_number and range_date. They all work fine but text and auto_complete are always empty. Here is my columns output when using all the filter types I just mentioned.

"columns":[

<!-- This is an hidden column with no filter ->
    {
        "data":"",
        "name":"Expand",
        "searchable":"true",
        "orderable":"false",
        "search":{
            "value":"",
            "regex":"false"
        }
    },
<!-- This one has multi_select set with value 2 and 3 ->
    {
        "data":"1",
        "name":"Sales channel",
        "searchable":"true",
        "orderable":"true",
        "search":{
            "value":"2|3",
            "regex":"true"
        }
    },
<!-- This one has text where I typed XXXXXX but as you can see search.value is empty ->
    {
        "data":"2",
        "name":"Order number",
        "searchable":"true",
        "orderable":"true",
        "search":{
            "value":"",
            "regex":"false"
        }
    },
<!-- Here we have a range_date -->
    {
        "data":"3",
        "name":"Order date",
        "searchable":"true",
        "orderable":"true",
        "search":{
            "value":"2024-02-01-yadcf_delim-2024-02-29",
            "regex":"false"
        }
    },
<!-- Lastly range_number -->
    {
        "data":"4",
        "name":"Quantity",
        "searchable":"true",
        "orderable":"true",
        "search":{
            "value":"1-yadcf_delim-5",
            "regex":"false"
        }
    },

]

And here is my configuration.

yadcf.init(table, [

                    {
                        column_number: 1,
                        filter_container_id: 'sales_channel',
                        filter_type: 'multi_select',
                        data: '{$filters.channels}',
                        data_as_is: true
                    },
                    {
                        column_number: 2,
                        filter_container_id: 'order_number',
                        filter_type: 'text',
                        filter_delay: 500
                    },
                    {
                        column_number: 3,
                        filter_container_id: 'order_date',
                        filter_type: 'range_date',
                        date_format: 'yyyy-mm-dd',
                        filter_delay: 500
                    },
                    {
                        column_number: 4,
                        filter_container_id: 'quantity',
                        filter_type: 'range_number',
                        filter_delay: 500
                    },
                ],

No errors in console. It all works fine from pagination to sorting asc/desc, export (pdf, copy, excel, pdf), column visibility (hide/show dropdown), server-side filters and orders. Same goes for YADCF fiters with the exception of text and auto_complete. Values never reach the server no matter what.

Let me know if you need an example but keep in mind it would be pretty hard to for me to provide one since we're talking of server-side processing with real data.

p.s. Starred this project. It is awesome. Really good job @vedmack

Kian987 commented 7 months ago

I managed to find the source of the problem.

I am placing all filters in a dedicated div (an accordion) using filter_container_id. The issue was that I still had filters_position: 'footer' in yadcf.init(). Long story short yadcf was unable to get the val() of text and auto_complete due to this jQuery selector:

.dataTables_scrollFoot#yadcf-filter--table-3

I had no .dataTables_scrollFoot in my page but yadcf was expecting it due to filters_position: 'footer'. I simply had to remove filter_position.

vedmack commented 7 months ago

@Kian987 thanks for the update