From a45c2fec2545d8ddb9e0038f56e0cd82d17b838f Mon Sep 17 00:00:00 2001 From: ClosedEyesSeeing Date: Mon, 3 Apr 2023 20:27:48 -0400 Subject: [PATCH] Adding natural sorting as a sorting strategy Using the 'numeric' and 'sensitivity' options in localCompare to provide a Natural Sort strategy. --- src/jsgrid.sort-strategies.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/jsgrid.sort-strategies.js b/src/jsgrid.sort-strategies.js index 6b46e6b5..8dfbb261 100755 --- a/src/jsgrid.sort-strategies.js +++ b/src/jsgrid.sort-strategies.js @@ -17,6 +17,19 @@ return ("" + str1).localeCompare("" + str2); }, + + stringNaturalSort: function(str1, str2) { + if(!isDefined(str1) && !isDefined(str2)) + return 0; + + if(!isDefined(str1)) + return -1; + + if(!isDefined(str2)) + return 1; + + return ("" + str1).localeCompare("" + str2, undefined, { numeric: true, sensitivity: 'base' }); + }, number: function(n1, n2) { return n1 - n2;