Search code examples
javascriptjquerytablesorter

tablesorter widget filter any match. How to only have search all columns (remove search for individual columns)


I'm trying to add a search filter to tablesorter but the only widget i could find adds a search for all columns and a search input for each individual column. I only want the search for all columns active and the functionality of searching in individual columns disabled.

This is the JS `$(function() {

var $table = $('table').tablesorter({
    theme: 'blue',
    widgets: ["zebra", "filter"],
    widgetOptions : {
        // filter_anyMatch replaced! Instead use the filter_external option
        // Set to use a jQuery selector (or jQuery object) pointing to the
        // external filter (column specific or any match)
        filter_external : '.search',
        // add a default type search to the first name column
        filter_defaultFilter: { 1 : '~{query}' },
        // include column filters
        filter_columnFilters: true,
        filter_placeholder: { search : 'Search...' },
        filter_saveFilters : true,
        filter_reset: '.reset'
    }
});
// make demo search buttons work
$('button[data-column]').on('click', function(){
    var $this = $(this),
        totalColumns = $table[0].config.columns,
        col = $this.data('column'), // zero-based index or "all"
        filter = [];

    // text to add to filter
    filter[ col === 'all' ? totalColumns : col ] = $this.text();
    $table.trigger('search', [ filter ]);
    return false;
});

});`

Here is a link to the table

The search input in each column is what i want removed.

thanks for the help


Solution

  • In the code above, column filters are being enabled:

    // include column filters
    filter_columnFilters: true,
    

    Set this option to false and the filter row will not be created (see filter_columnFilter option).