Serching by columns whith checkboxes

Serching by columns whith checkboxes

laynierlaynier Posts: 14Questions: 2Answers: 0

If I am using a simple search by column like the code below:


$(document).ready(function() { $('#example1 thead tr').clone(true).appendTo( '#example1 thead' ); $('#example1 thead tr:eq(1) th').each( function (i) { var title = $(this).text(); if(title != 'Action'){ $(this).html( '<input type="text" placeholder="Search '+title+'" />' ); $( 'input', this ).on( 'keyup change', function () { if ( table.column(i).search() !== this.value ) { table .column(i) .search( this.value ) .draw(); } } ); } else $(this).text(''); } ); var table = $('#example1').DataTable( ); });

But some colums are checkboxes, only marked or not, how can I achieve the same that with text columns?
Write true or false did not work out...

I have tried with:

 if(title == 'Active'){
                        $(this).html('<select id="select_yn" class="form-control form-control-sm" >' +
                            '<option value="" selected >Select</option>' +
                            '<option value= true >Yes</option>' +
                            '<option value= false>No</option>' +
                            '</select>');
                        $('#select_yn', this).on('keyup change', function () {                 
                            if (table.column(i).search() !== this.value) {
                                table
                                    .column(i)
                                    .search(parseInt(this.value))
                                    .draw();
                            }
                        });
}

That failed... Also tried usin 0 and 1 in the values of the option, nothing so far... any idea?

Replies

Sign In or Register to comment.