From 3b5161a5ba8cd4bcc302c218ffeca41fd47af27a Mon Sep 17 00:00:00 2001 From: Mottie Date: Tue, 29 Apr 2014 07:12:06 -0500 Subject: [PATCH] Filter: make sure textSorter is getting strings --- js/jquery.tablesorter.js | 2 ++ js/jquery.tablesorter.widgets.js | 3 ++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/js/jquery.tablesorter.js b/js/jquery.tablesorter.js index 9f851441..b3a13955 100644 --- a/js/jquery.tablesorter.js +++ b/js/jquery.tablesorter.js @@ -1243,6 +1243,8 @@ }; // Natural sort - https://github.com/overset/javascript-natural-sort (date sorting removed) + // this function will only accept strings, or you'll see "TypeError: undefined is not a function" + // I could add a = a.toString(); b = b.toString(); but it'll slow down the sort overall ts.sortNatural = function(a, b) { if (a === b) { return 0; } var xN, xD, yN, yD, xF, yF, i, mx, diff --git a/js/jquery.tablesorter.widgets.js b/js/jquery.tablesorter.widgets.js index dcddf060..32711f73 100644 --- a/js/jquery.tablesorter.widgets.js +++ b/js/jquery.tablesorter.widgets.js @@ -1082,7 +1082,8 @@ ts.filter = { // sort parsed select options cts = c.textSorter || ''; parsed.sort(function(a, b){ - var x = a.p, y = b.p; + // sortNatural breaks if you don't pass it strings + var x = a.p.toString(), y = b.p.toString(); if ($.isFunction(cts)) { // custom OVERALL text sorter return cts(x, y, true, column, table);