grid-js / gridjs

Advanced table plugin
https://gridjs.io
MIT License
4.39k stars 240 forks source link

Separate display and sort values #1434

Open GitRon opened 6 months ago

GitRon commented 6 months ago

Is your feature request related to a problem? Please describe.

Imagine I have a column with links to projects where you display the project name as the clickable text. It's not possible to sort this column because every link starts with a "<".

Same goes for localized numbers. The float 10,000.00 would be 10.000,00 in German. Gridjs will sort this as a string, therefore totally wrong.

Describe the solution you'd like

The old jQuery datatable package solves it by separating the value where you want to sort by and the display value. I think that could be a great solution. (not the way they do it, tough 😅)

Instead of having to implement a custom sorting algorithm, we could add a new attribute to this object called sortBy or sortValue. If this is set, it will be used to sort the column by.

Supplemantal: Not sure if it's really that easy... unless you add the data via the columns and not via the table-wide data attribute.

Describe alternatives you've considered

I tried to implement the custom sorting algorithm but it creates MUCH redundant code and bloats my tables for a very defaulty case.

Additional context

I'm a Python developer, so I unfortunately can't help with a PR. But the solution could be easy to implement and a huge improvement to your package.

Best
Ronny