kylefox/jquery-tablesort

Disable column

Closed this issue · 5 comments

Is there any specific way to disable a column from trying to sort?

I tried this, but I don't think it's working.

$('th.type-null').data('sortBy', function (th, td, sorter) {
return false;
});

Out of curiosity, what is your solution doing that seems wrong? I seems like it should work...

Probably the best thing to try is binding to the custom "click.tablesort" event on the th you want disabled, and then preventing the event. I believe the method you want is event.stopImmediatePropagation(), so something like:

$('th.type-null').on('click.tablesort', function (event) {
    event.stopImmediatePropagation();
    return false; // May not need the return statement.
});

To be honest it's been a while since I used this plugin, so you'll probably need to experiment a bit and dig into the plugin code!

Yea I started looking through the code last night. I got the disable column working the way I wanted it to.

I am running into an issue with Chrome and sorting a column with all the same values. You'd think that it just wouldn't sort since every value was the same. I made a demo in jsFiddle to demonstrate the issue. This only happens in Chrome, not Firefix. Do you think it has to do with the string comparison differences between browsers. I tried .trim() and toLowerCase(), neither made a difference.

http://jsfiddle.net/nAMbs/1/

Yea I started looking through the code last night. I got the disable column working the way I wanted it to.

Cool. Mind sharing how you ended up doing this?

Regarding your jsFiddle, I see what you mean. The internal sort method does indeed return 0 for each item in the column with similar values, so it's not related to how the browsers are comparing things.

The only thing that comes to mind is maybe Chrome iterates over the rows in a different (and unexpected) manner than Firefox does, and as a result re-appends the tr elements in a weird order.

I ended up bailing and going with https://github.com/joequery/Stupid-Table-Plugin it was able to get around the Chrome/FF issue.

Okay, good to know -- thanks for the link!