Easy individual column searching (multiple columns)

Easy individual column searching (multiple columns)

kmd1970kmd1970 Posts: 36Questions: 8Answers: 1
edited November 2015 in DataTables 1.10

For anyone looking for a quick solution to filter multiple columns outside of the Datatable structure.

This method simply uses generic form inputs (by class selector), passing in the filtered column index using data-* attributes.

http://jsfiddle.net/kmd1970/jz1zvvr1/

Also If you want to clear the input values when searching globally

$('.filter').on('keyup change', function () {
        //clear global search value
        dtable.search('');
        dtable.column($(this).data('columnIndex')).search(this.value).draw();
});
    
$( ".dataTables_filter input" ).on( 'keyup change',function() {
       //clear all column search values
        dtable.columns().search('');
       //clear all form input values
       $('.filter').val('');
}); 

Replies

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin

    Nice one - thanks for sharing this with us!

    Allan

  • callejascallejas Posts: 3Questions: 1Answers: 0

    Great!.
    but if the search is performed via button click ? Searching all input text at once
    How to make ? Thank´s

  • kmd1970kmd1970 Posts: 36Questions: 8Answers: 1
    $('.filter-button').on('click', function () {
            //clear global search values
            dtable.search('');
            $('.filter').each(function(){ 
            if(this.value.length){
              dtable.column($(this).data('columnIndex')).search(this.value);
            }
            });
            dtable.draw();
        });
    

    http://jsfiddle.net/kmd1970/yLxowxen/

This discussion has been closed.