From e9bbec48b9470592ce0387d34317eeeb56633925 Mon Sep 17 00:00:00 2001 From: Mottie Date: Thu, 13 Mar 2014 18:47:40 -0500 Subject: [PATCH] Fix numberSorter js error & add test --- js/jquery.tablesorter.js | 2 +- testing/testing.js | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/js/jquery.tablesorter.js b/js/jquery.tablesorter.js index 071ccf7e..e2721aeb 100644 --- a/js/jquery.tablesorter.js +++ b/js/jquery.tablesorter.js @@ -729,7 +729,7 @@ } // fall back to built-in numeric sort // var sort = $.tablesorter["sort" + s](table, a[c], b[c], c, colMax[c], dir); - sort = c.numberSorter ? c.numberSorter(x[col], y[col], dir, colMax[col], table) : + sort = c.numberSorter ? c.numberSorter(a[col], b[col], dir, colMax[col], table) : ts[ 'sortNumeric' + (dir ? 'Asc' : 'Desc') ](a[col], b[col], num, colMax[col], col, table); } else { // set a & b depending on sort direction diff --git a/testing/testing.js b/testing/testing.js index 3ae48af3..eafade2c 100644 --- a/testing/testing.js +++ b/testing/testing.js @@ -94,7 +94,7 @@ Core plugin tested OPTIONS: cssAsc, cssChildRow, cssDesc, cssHeader, cssHeaderRow, cssInfoBlock, dateFormat, emptyTo, headerList, headers, ignoreCase, initialized, parsers, sortList, sortLocaleCompare, sortReset, stringTo, tableClass, - usNumberFormat, widgets (just zebra), sortAppend, sortForce, sortMultiSortKey, sortResetKey + usNumberFormat, widgets (just zebra), sortAppend, sortForce, sortMultiSortKey, sortResetKey, numberSorter METHODS: addRows, applyWidgets, destroy, sorton, sortReset, update/updateRow, updateAll, updateCell @@ -186,6 +186,9 @@ $(function(){ e.which = 1; e.shiftKey = true; c.$headers.eq(5).trigger(e); + }, + numberSorter: function(a, b, dir){ + return dir ? a-b : b-a; } }); @@ -520,7 +523,7 @@ $(function(){ /************************************************ test sortForce, sortAppend, sortMultiSortKey and sortResetKey options ************************************************/ - asyncTest( "sortForce, sortAppend, sortMultiSortKey & sortResetKey", function(){ + asyncTest( "sortForce, sortAppend, sortMultiSortKey & sortResetKey; and numberSorter option", function(){ expect(3); var count = 0; tester.cacheCompare( table4, 3, [ 2, 1, 7, 6, 5, 3, 4, 8, 9, 10 ], 'force x2 + sorted x2 + append x2, ascending' );