wet-boew / wet-boew-styleguide

A style guide for the Web Experience Toolkit.
http://wet-boew.github.io/wet-boew-styleguide/index-en.html
36 stars 32 forks source link

Tables with numbers can't be ordered if they have units #269

Open danielt113 opened 8 years ago

danielt113 commented 8 years ago

I have a table that shows distances to passport offices. The distance column is sorted numerically but when I put in "Km" after each number it sorts it alphabetically. So it sorts looks like:

  1. 8 km
  2. 8,898 km
  3. 806 km
  4. 849 km

Is it possible to have units after each number in the cell without affecting the sorting method?

RobJohnston commented 8 years ago

I think that as soon as you added letters to the distance, the sorting changed from numeric to string. Style-wise, I remember that my science teachers would have been upset with me if I didn't write the units in the column header.

But maybe you could benefit from the "Hidden title numeric sorting" article on the DataTables website: https://datatables.net/plug-ins/sorting/title-numeric

ghost commented 5 years ago

I would look into: https://www.datatables.net/examples/advanced_init/html5-data-attributes.html.

pcwsmith commented 5 years ago

The Canada.ca Content Style Guide has comprehensive guidance on tables: https://www.canada.ca/en/treasury-board-secretariat/services/government-communications/canada-content-style-guide.html#wp5-3

(and @RobJohnston is right - it is good style to put the units in to header)