yadcf: exFilterColumn function is not working

1.5k views Asked by At

I'm using datatables and yadcf on my website. Everything is working fine. In some cases I want to prefilter a column.

yadcf.init(oTable, [ {
                        column_number : 1,
                        filter_default_label : "",
                        filter_reset_button_text : false,
                        filter_type : "multi_select",
                        select_type : 'select2'

                    }, {
                        column_number : 2,
                        filter_default_label : "",
                        filter_reset_button_text : false,
                        filter_type : "multi_select",
                        select_type : 'select2'

                    }, {
                        column_number : 3,
                        filter_default_label : "",
                        filter_reset_button_text : false,
                        filter_type : "multi_select",
                        select_type : 'select2' 

                    }, {
                        column_number : 5,
                        filter_default_label : "",
                        filter_reset_button_text : false,
                        filter_type : "multi_select",
                        select_type : 'select2'

                    }, {
                        column_number : 6,
                        filter_default_label : "",
                        filter_reset_button_text : false,
                        filter_type : "multi_select",
                        select_type : 'select2'

                    } ]);

Until this point everything works fine. But when I add:

yadcf.exFilterColumn(oTable, [[3, 'WNC402']]);

there does not appear any filter. The console output error is:

jquery.dataTables.yadcf.js:688 Uncaught TypeError: selected_value.join is not a function
    at yadcfMatchFilterString (jquery.dataTables.yadcf.js:688)
    at Object.exFilterColumn (jquery.dataTables.yadcf.js:3792)
    at HTMLDocument.<anonymous>
    at i (jquery-2.2.4.min.js:2)
    at Object.fireWith [as resolveWith] (jquery-2.2.4.min.js:2)
    at Function.ready (jquery-2.2.4.min.js:2)
    at HTMLDocument.J (jquery-2.2.4.min.js:2)

the site still loads properly and I even can set the filters manually. But the function should do the job.

my datatables version is: 1.10.12

my yadcf version is: 0.8.9

some links:

https://datatables.net/

https://github.com/vedmack/yadcf

Thank you.

3

There are 3 answers

2
Daniel On BEST ANSWER

Please read the docs and the usage example of filtering mutiselect column

yadcf.exFilterColumn(oTable, [[0, ['Some Data 1','Some Data 2']]]); // for pre filtering multi select filter you should use array with values (or an array with single value)

Since its a multi select filter you have to provide the filter value inside an array.

0
Oskar Westmeijer On

ok I found something. Instead using yadcf's exColumnFilter function, I used Datatables search function.

oTable.columns(3).search("WNC402").draw();

works like a charm. The Filter appears now and is even removable in my case.

I hope this will also help someone else.

0
Murat Çapanoğlu On

I have solved the issue with jQuery in init complete event of datatable.

$("#yadcf-filter--kt_datatable-28").val("Active");
$("#yadcf-filter--kt_datatable-28").trigger("change");