datatable: sort numbers numerically
This commit is contained in:
@ -36,16 +36,28 @@ function sortTable(n) {
|
||||
one from current row and one from the next: */
|
||||
x = rows[i].getElementsByTagName("TD")[n];
|
||||
y = rows[i + 1].getElementsByTagName("TD")[n];
|
||||
xval = x.innerHTML;
|
||||
yval = y.innerHTML;
|
||||
if (!isNaN(parseInt(xval))) {
|
||||
xval = parseInt(xval);
|
||||
} else {
|
||||
xval = xval.toLowerCase();
|
||||
}
|
||||
if (!isNaN(parseInt(yval))) {
|
||||
yval = parseInt(yval);
|
||||
} else {
|
||||
yval = yval.toLowerCase();
|
||||
}
|
||||
/* Check if the two rows should switch place,
|
||||
based on the direction, asc or desc: */
|
||||
if (dir == "asc") {
|
||||
if (x.innerHTML.toLowerCase() > y.innerHTML.toLowerCase()) {
|
||||
if (xval > yval) {
|
||||
// If so, mark as a switch and break the loop:
|
||||
shouldSwitch = true;
|
||||
break;
|
||||
}
|
||||
} else if (dir == "desc") {
|
||||
if (x.innerHTML.toLowerCase() < y.innerHTML.toLowerCase()) {
|
||||
if (xval < yval) {
|
||||
// If so, mark as a switch and break the loop:
|
||||
shouldSwitch = true;
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user