-
Notifications
You must be signed in to change notification settings - Fork 753
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
how can I get the current sortOrder in the sortEnd event? #1208
Comments
Hi @finira! The $(function () {
$('table')
.on('sortEnd', function(){
$('.sortlist').text(this.config.sortList);
})
.tablesorter({
theme: 'blue'
});
}); I'm not sure what you want to do with the information, but please be aware that the console.log(this.config.sortList);
// [[0,1],[2,0]]
// [0,1] = column 0 (first column), descending sort
// [2,0] = column 2 (third column), ascending sort Alternatively, the $(function() {
$('table')
.on('sortEnd', function() {
var c = this.config,
list = '';
$.each(c.sortList, function(i, v) {
list += '<li>' + c.$headerIndexed[v[0]].attr('aria-label') + '</li>';
});
$('.sortlist').html('<ul>' + list + '</ul>');
})
.tablesorter({
theme: 'blue'
});
}); |
Hi @Mottie ! At line 203 , I added a variable currentSortOrder to remenber the current order.
and a function getCurrentOrder which return the currentSortOrder . and in function multisort ,I invoke the putCurrentOrder to set current order from sortList. (only multisort is used in my program so I invoke the method in this function) and I can get the current order like this: That's my temp plan,and I complete it ,thank you ~ |
I wouldn't recommend changing the plugin code. The reason is that when you update the tablesorter core code, all that extra code will need to be added back. The best solution would be best to loop through each |
Thank you . |
Hmmm, I might consider adding something like the following code... (demo): $.tablesorter.currentSortLanguage = {
0: 'asc',
1: 'desc',
2: 'unsort'
};
$.tablesorter.currentSort = function(table) {
// allow passing DOM & jQuery object
table = $(table)[0];
var indx,
c = table.config,
lang = $.tablesorter.currentSortLanguage,
unsort = lang[2],
// see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/fill
// order = new Array(c.columns).fill(unsort),
// the above ES6 will not work in all browsers, so
// we're stuck with this messy code to fill the array:
order = Array
.apply(null, Array(c.columns))
.map(String.prototype.valueOf, unsort),
sortList = c.sortList,
len = sortList.length;
for (indx = 0; indx < len; indx++) {
order[sortList[indx][0]] = lang[sortList[indx][1]];
}
return order;
}; It can be used as follows: $(function() {
$('table')
.on('sortEnd', function() {
console.log($.tablesorter.currentSort(this));
})
.tablesorter({
theme: 'blue',
widgets: ['zebra']
});
}); Or, you can call This code might just be more bloat added to the core, so maybe I'll add it into a separate |
Woo!! |
I want to get the current sortOrder in every sortend event.(desc or asc)
so how can I get it ?
The text was updated successfully, but these errors were encountered: