2
votes

I have columns in a react Ag-Grid that sort percentage columns like 5.08% as a string. how can I get ag-grid to sort them as number values instead? the data coming from the server is already formatted for 0.00 and there is a cell renderer that appends the % sign. Thank you

1

1 Answers

4
votes

In the column definition you can provide a comparator function. This function is provided various parameters:

percentColumn.comparator = function (valueA, valueB, nodeA, nodeB, isInverted) {
    return parseFloat(valueA) - parseFloat(valueB);
}

I am not quite sure how having the cell renderer would affect what valueA and valueB are, but doing something like the above should work.