I have a table in which there is a salary field which is rounded and formatted to use comma separated figures within like 1,23,344
Now when I try to apply sort it doesnt work.
My sandbox url is: https://codesandbox.io/s/quiet-feather-q4jn4
It's sorting by string. The table will look at the data, and if it's a number, it'll sort it like a number, and if it's a string, it'll sort it like a string. If you want a custom sort, you have to use the customSort option:
https://codesandbox.io/s/quizzical-kalam-eeeqx?file=/src/App.js
Note: That's just a quick and dirty example, and probably doesn't sort exactly how you want. But that's how you override how sorting works.
Also, I noticed your Start Date wasn't sorting correctly either. This is because the table will use the value returned from customBodyRender for sorting (which is a string). To avoid this, you can use customBodyRenderLite (which doesn't effect filtering or sorting), I updated the example above to show this.
Hey That was good lead though, I missed something in my example which I noticed later, that I didnt saved my sandbox after change by implementing the formatNumber function to all the salaries, the solution or the direction didnt worked with it...
This is the updated sandbox link with your solution intact, not working:
You have to process your input, parseInt can't handle commas. Here's a version where the commas are removed:
https://codesandbox.io/s/inspiring-lederberg-nde7o?file=/src/App.js
Essentially, inside of customSort you'll want to transform your data to numbers so they can be compared, or transform them to strings that would sort correctly when compared.
Thats an excellent solution!!! Thank You So Much!!
Most helpful comment
You have to process your input, parseInt can't handle commas. Here's a version where the commas are removed:
https://codesandbox.io/s/inspiring-lederberg-nde7o?file=/src/App.js
Essentially, inside of customSort you'll want to transform your data to numbers so they can be compared, or transform them to strings that would sort correctly when compared.