tofsjonas / sortable

Vanilla JavaScript table sort
The Unlicense
423 stars 49 forks source link

Prefix support for Kilo, Mega, Giga, ... #33

Closed dumtux closed 1 year ago

dumtux commented 1 year ago

When I have a table like this,

Name Value
Party A 250
Party B 1.2k
Party C 16200
Party D 2.8M

Is there a way to make sorting correct.y?

tofsjonas commented 1 year ago

That's what the data-sort attribute is for:

...
<td>Party B</td>
<td data-sort="1228.8">1.2k</td>
...
<td>Party D</td>
<td data-sort="2936012.8">2.8M</td>
...

Are you the one generating the html table? Or do you need to solve this with javascript only?

dumtux commented 1 year ago

Thank you. I generate the table from JSON data, thus, this can solve my problem quickly.