tablesorter
tablesorter copied to clipboard
Override tablesorter instance
I already asked this on SO a while ago but got no answers, so trying my luck here:
I have a general tablesorter class, .tablesorter, with which I associate the simplest tablesorter: $('.tablesorter').tablesorter();
However, in some cases I want to override this, for example with disabled sort headers, etc. However, this doesn't seem to work, and I am only able to get the original behavior. Is this normal? Is there anything I can do to make this work?
Thanks in advance.
Hi @Ynhockey!
I'm not sure if this'll answer your question, but if you don't want a table to be made sortable, don't include the tablesorter
class name.
To disable a header cell initially, set the headers
option to false
(demo)
$("table").tablesorter({
headers: {
0: { sorter: false }
}
});
To disable specific columns dynamically, toggling the header cell's sortDisabled
property (demo), then apply a sort:
$('table').tablesorter();
$('button').click(function(){
// disable sorting for a specific column
$('th')[1].sortDisabled = true;
// remove any sorting
$('table').trigger('sorton', [[[0,2]]]);
});