Search code examples
widgetconfigtablesorter

tablesorter update widgetOptions for columnSelector


i want to search column by name enter image description here

i tried to do this manually by

                table[0].config.widgetOptions.columnSelector_columns = {
                    2: true,
                    3: false
                };

and call table.trigger('update'); or table.trigger('applyWidgets'); or table.trigger('refreshColumnSelector'); but nothing working also tried refresh Widgets but its not working too...


Solution

  • * Please note * this widget & code only work on my fork of tablesorter.

    You could target all (or both in this case) tables, then use the jQuery .each() method like this:

    $(".tablesorter")
        .each(function(i, table){
            var $table = $(table);
            $table.tablesorter({
                // ...
                widgetOptions: {
                    // ...
                    columnSelector_container : $('#columnSelector' + ( i + 1 )),
                    // ...
                }
            })
            .bind('filterEnd', function(e, filter){
                // the current number of filtered rows is contained in config.filteredRows
                $table.prev('div').find('.filterCount').text( table.config.filteredRows );
            });
        });
    

    and as for the css, you can group them together:

    #colSelect1:checked + label, #colSelect2:checked + label {
        background: #5797d7;
        border-color: #555;
    }
    #colSelect1:checked ~ #columnSelector1, #colSelect2:checked ~ #columnSelector2 {
        display: block;
    }