Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

reverse default sort order to DESC #8

Open
twentyfortysix opened this issue Oct 26, 2015 · 1 comment
Open

reverse default sort order to DESC #8

twentyfortysix opened this issue Oct 26, 2015 · 1 comment

Comments

@twentyfortysix
Copy link

hello
how can I reverse the initial order from ASC to DESC?

The original documentation says:

Sort in descending order first

Making sorttable sort your columns in descending order first rather than ascending order requires editing sorttable.js. Find the line:

row_array.sort(this.sorttable_sortfunction);
and after it, add a new line:

row_array.reverse();

but that is no longer the case, as the code went thru refactoring ;)
thx

@twentyfortysix
Copy link
Author

ok, I found the code
sort_numeric: function(a,b) { var aa = parseFloat(a[0].replace(/[^\-\d.]/g,'')) || 0; var bb = parseFloat(b[0].replace(/[^\-\d.]/g,'')) || 0; return aa - bb; },

and change it to:
sort_numeric: function(a,b) { var aa = parseFloat(a[0].replace(/[^\-\d.]/g,'')) || 0; var bb = parseFloat(b[0].replace(/[^\-\d.]/g,'')) || 0; return bb - aa; },

(changed the aa, bb comparison)

It'll be better to have a option or something like that not to hack the code ;) But that is not all, indeed, the arrow shows previous direction, which corresponds to the overall default sorting direction... What a fun :)


update:
here is how it works for me
I changed the arrows on row 24:
ARROWS: /MSIE [5-8]\.\d/.test(navigator.userAgent) ? ['&nbsp<font face="webdings">5</font>','&nbsp<font face="webdings">6</font>'] : ['&nbsp;&#x25BE;','&nbsp;&#x25B4;'],
plus reversed the default sorting logic on row 286:
if (!inverse) sortle.val.reverse();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant