How to filter multiple tables on different columns?

How to filter multiple tables on different columns?

doncidonci Posts: 11Questions: 4Answers: 0
edited August 2017 in Free community support

I have 4 tables on one page and individual column filters for each table (server side processing).
I would like to add an input field where the user can write a value which will be searched in all tables.
However, I have to stick on column search and specify which column pro table can be filtered.
At the same time I want to disable individual column filters when user is filtering all tables.

Do you have any idea how to do that?

This is how I handle the seach for individual columns now:

$(function() {
// Setup - add a text input to each footer cell
$('.searchcol').each(function() {
var title = $(this).text();
$(this).html('<input type="text" placeholder="Search ' + title + '" />');
});
var mygender = $('#gender').DataTable( {
"serverSide": true,
"processing": true,
"paging": true,
"ajax": "gender",
'order': [
[5, 'desc']
],
dom: 'Blrtip',
});
// Function for searching each column separately
mygender.columns().every(function() {
var that = this;
$('input', this.footer()).on('keyup change', function() {
if (that.search() !== this.value) {
// true refers to regex = true
that
.search(this.value, true)
.draw();
}
});
});

Answers

  • doncidonci Posts: 11Questions: 4Answers: 0

    Resolved:

           $('.searchitem').on( 'keyup', function () {
               myfirsttable
                  .columns( 0 )
                  .search( this.value )
                 .draw();
               mysecondtable
                  .columns( 3 )
                  .search( this.value )
                 .draw();
    
            } );
    

    <input class="searchitem">

This discussion has been closed.