Column multiple select filter

Column multiple select filter

Muhammad IzzatMuhammad Izzat Posts: 22Questions: 10Answers: 0

Hello everyone and Mr.Allan, base from this filter datatables.net/examples/api/multi_filter_select.html how can I upgrade the filter into a multiple select checkbox, for example in the example table I want to filter select NewYork, San Francisco
and London.

Any help is much appreciated, thanks.

Answers

  • jazjaz Posts: 16Questions: 3Answers: 0

    There may be an easier way, but I use the regex parameter in the search function. Here is an example from some of my code:

    $("#id_of_multi_select").change(function(){
                //assemble the regex expression for multiple select values
                var regEx = $(this).find(':selected').map(function() {
                        return $( this ).text();
                    })
                    .get()
                    .join( "|" );
                table.column( index_of_column_to_search_on ).search(  regEx, true, false ).draw();
            });
    

    Note: I don't use the same syntax to create my select dropdown - I create it elsewhere and then just use the id to attach the change function. The important part is assembling the regular expression from the selected options and then using that to search on the column that you want.

  • Muhammad IzzatMuhammad Izzat Posts: 22Questions: 10Answers: 0

    Hey jaz, thanks for your reply apologies for he late reply, currently I'm having issue appending the data in my column into my select field so I had to postpone this part till fix that, will get back to this immediately afterward, thank ou so much

  • stephenbjstephenbj Posts: 2Questions: 1Answers: 0

    Hi,
    i have multi select in that I am select cat and dog I convert into the format which you mention on earlier comment like (cat|dog) it is not working properly when my data is:


    cat india | xxx | xxx


    cat uk | xxx | xxx


    cat | xxx | xxx --------------> I want this row alone


    dog | xxx | xxx


    god PK | xxx | xxx


  • kthorngrenkthorngren Posts: 21,330Questions: 26Answers: 4,951

    See if this recent thread, discussing multiple selects when searching columns, helps:
    https://datatables.net/forums/discussion/51547

    Kevin

This discussion has been closed.