My data:
data: [
["A","2"],
["B","100"],
]
I was expecting it to sort by amount: 2 then 100, but it's the opposite. First row shows 100, second row shows 2. Is there a way to sort by the actual amount rather than this numeric ordering?
new gridjs.Grid({
columns: [
"Fecha",
{
name: "Cantidad",
sort: {
compare: (a, b) => {
if (parseFloat(a) > parseFloat(b)) {
return 1;
} else if (parseFloat(b) > parseFloat(a)) {
return -1;
} else {
return 0;
}
},
},
},
"Tipo",
"Origen",
]
As "2" and "100" are interpreted as string - the sort order is alphanumeric instead of numeric.
Try
data: [
["A",2],
["B",100],
]
instead to sort by the numbers.