Reputation: 3476
I'm using ag-grid and I have a small issue with numeric filtering:
As you can see the sorting is going well unless the numbers are 2xxx but it start to be confusing as soon as it reach 3 numbers.
What I do expect is the sorting starting from 500 and go up to 2400+ or the inverse. Maybe I don't know about a special option to add to achieve this, I'm getting crazy trying different options but nothing seems to work. I hope you can help. Thanks.
UPDATE:
I reproduced the issue on the original ag-grid example on filtering: https://plnkr.co/edit/Tn9ZeCH4fmLr2ZHQPivQ?p=preview I just mutated the year values and as you can see it is not sorting as expected.
if (r.year === 2008) r.year = 860
if (r.year === 2012) r.year = 920
Upvotes: 2
Views: 1856
Reputation: 38164
The reason of this is that it sorts data as string, not number. So just add custom sorting into your comparator
for your yeat
field:
var numberSort = (num1, num2) => {
return num1 - num2;
};
var columnDefs = [
/*The other code is omitted for the brevity*/
{headerName: "Year", field: "year", width: 90, comparator: numberSort},
/*The other code is omitted for the brevity*/
];
UPDATE:
It looks like you need to add sortable
to gridoptions
:
var gridOptions = {
defaultColDef: {
filter: true,
sortable: true
},
}
Upvotes: 4