Skip to content

Commit

Permalink
Added support for passing a 'compare' function used to sort
Browse files Browse the repository at this point in the history
  • Loading branch information
Justin Sharp committed Sep 30, 2016
1 parent e08d8b7 commit 1f49dc6
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions jquery.tablesort.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,7 @@
}

sortedMap.sort(function(a, b) {
if (a.value > b.value) {
return 1 * direction;
} else if (a.value < b.value) {
return -1 * direction;
} else {
return 0;
}
return self.settings.compare(a.value, b.value) * direction;
});

$.each(sortedMap, function(i, entry) {
Expand Down Expand Up @@ -111,7 +105,16 @@
$.tablesort.defaults = {
debug: $.tablesort.DEBUG,
asc: 'sorted ascending',
desc: 'sorted descending'
desc: 'sorted descending',
compare: function(a, b) {
if (a > b) {
return 1;
} else if (a < b) {
return -1;
} else {
return 0;
}
}
};

$.fn.tablesort = function(settings) {
Expand Down

1 comment on commit 1f49dc6

@larsnaesbye
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couldn't this be used for a type of natural sorting, by supplying a naturalsort function?

Please sign in to comment.