Search code examples
javascriptjquerytablesorter

Tablesorter - One column table, remove sorting but keep search for that column


So here is a link to the table. I can't disable the sorting feature without also disabling the search for that column as well. Im using the filter widget external search incase that helps.

Here is the JS coding

$(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: false,
        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;
});

});


Solution

  • All you need to do is add a "sorter-false" class name to the header:

    <th class="column-1 sorter-false"></th>
    

    Here is a demo