Regex search with checkbox

Regex search with checkbox

jsantos06jsantos06 Posts: 1Questions: 1Answers: 0

I have a table that I need to apply multiple filters to a single column. I'm following the regex tutorial but cant seem to get it working right, I'm using checkboxes as the input type.
If I check one checkbox, the filter works. When more than one is checked, it doesn't work. any advice?
Below is my code.

Thanks in advance

                            $(document).ready(function(){

                                var table = $('#names').dataTable({
                                    "processing": true,
                                    "serverSide": true,
                                    "ajax": "/names-ajax.php",
                                    "pageLength":100,
                                    "bLengthChange":false,
                                    "info": false,
                                });
                                var search = this.value;
                                var searches = '';
                                $('.fName').change(function(){

                                    if($('.fName:checked').length>1){
                                        for(var i = 0; i < $('.fName:checked').length; i++){
                                            searches +=$('.fName:checked')[i].value+'|';
                                        }
                                        console.log(searches);
                                        table
                                            .column(0)
                                            .search(searches, true,)
                                            .draw();
                                    } else {
                                        table
                                            .column(0)
                                            .search(this.value)
                                            .draw();
                                    }
                                });
                                $('.mName').change(function(){
                                    table
                                        .column(7)
                                        .search(searches, true,)
                                        .draw();
                                });
                                $('.lName').change(function(){
                                    table
                                        .column(9)
                                        .search(searches, true,)
                                        .draw();
                                });
                            });
This discussion has been closed.