Skip to content

Commit

Permalink
sort by int if possible
Browse files Browse the repository at this point in the history
  • Loading branch information
lachlan-00 committed Apr 22, 2024
1 parent 7488bd6 commit 96327e6
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion public/lib/javascript/search.js
Expand Up @@ -99,7 +99,18 @@ var SearchRow = {

// Sort the keys based on their corresponding values in widget["1"]
keys.sort(function(a, b) {
return widget["1"][a].localeCompare(widget["1"][b]);
var valA = widget["1"][a];
var valB = widget["1"][b];

var intA = parseInt(valA, 10);
var intB = parseInt(valB, 10);

// Check if both values can be parsed as integers before sorting as strings
if (!isNaN(intA) && !isNaN(intB)) {
return intA - intB;
} else {
return valA.localeCompare(valB);
}
});

// Now use jQuery.each
Expand Down

0 comments on commit 96327e6

Please sign in to comment.