tablesorter icon indicating copy to clipboard operation
tablesorter copied to clipboard

Override tablesorter instance

Open Ynhockey opened this issue 7 years ago • 1 comments

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.

Ynhockey avatar Aug 15 '17 13:08 Ynhockey

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]]]);
});

Mottie avatar Apr 24 '18 14:04 Mottie