Search code examples
jquerygroupingtablesorter

TableSorter - Group plugin


I'm using the following plugin for the jQuery TableSorter to group my rows.

http://mottie.github.io/tablesorter/docs/example-widget-grouping.html

I have everything working as expected the only item I'm not able to get is when the page loads, I'd like to have the table already grouped. I tried to trigger the table header cell's click method but that isn't doing the trick either.

Is there an easy way to set a default grouping with this plugin (hopefully by column index).


Solution

  • All you need to do is define a sortList with whichever column you want sorted/grouped (only the first column is grouped); this will initialize the grouping widget (demo):

    $('table').tablesorter({
        theme: 'blue',
        sortList: [ [0, 0] ],
        widgets: ['zebra', 'group']
    });