mhodgson
07-02-2008, 12:05 PM
Hi,
Is there a way to sort mixed values (e.g. 2a, 2c, 2b, 3c, 1c, 5a).
I need to sort them by number then by letter (e.g 1c, 2a,2b,2c,3c,5a). There are only w letters, a,b,c and w on its own(no number in front).
The sorting script I have will only sort by integers or by strings.
example of part of the script- Maybe I need to change the letters to a numeric value? so w becomes 0, 2a becomes 21 and 2b becomes 22 and 3c becomes 31 and then allowing this bit to sort it.
Any suggestions?
// If the item matches a numeric pattern
if (itm.match(/(\d*,\d*$)|(^-?\d\d*\.\d*$)|(^-?\d\d*$)|(^-?\.\d\d*$)/)) {
// Replace anything that is not part of a number (decimal pt, neg sign, or 0 through 9) with an empty string.
sortValue = itm.replace(/[^0-9.-]/g,'');
// sortValue = sortValue.replace(/,/g,'');
if (isNaN(sortValue)) {
sortValue = 0;
} else {
sortValue = parseFloat(sortValue);
}
}
Is there a way to sort mixed values (e.g. 2a, 2c, 2b, 3c, 1c, 5a).
I need to sort them by number then by letter (e.g 1c, 2a,2b,2c,3c,5a). There are only w letters, a,b,c and w on its own(no number in front).
The sorting script I have will only sort by integers or by strings.
example of part of the script- Maybe I need to change the letters to a numeric value? so w becomes 0, 2a becomes 21 and 2b becomes 22 and 3c becomes 31 and then allowing this bit to sort it.
Any suggestions?
// If the item matches a numeric pattern
if (itm.match(/(\d*,\d*$)|(^-?\d\d*\.\d*$)|(^-?\d\d*$)|(^-?\.\d\d*$)/)) {
// Replace anything that is not part of a number (decimal pt, neg sign, or 0 through 9) with an empty string.
sortValue = itm.replace(/[^0-9.-]/g,'');
// sortValue = sortValue.replace(/,/g,'');
if (isNaN(sortValue)) {
sortValue = 0;
} else {
sortValue = parseFloat(sortValue);
}
}