Tabulator: Sort Bytes

Created on 25 Jul 2017  Â·  2Comments  Â·  Source: olifolkerd/tabulator

Hi,

is it possible to sort bytes or GB ascending and descending properly in tabulator.js? I couldn't find a way to make the column containing a disk size sorting properly.

Thanks.

Question - Ask On Stack Overflow

All 2 comments

Hi
I would recommend you to use a numerical value (like 4.25, 10248 or 0.012) representing the most common "scale" your data is (Megabyte, Gigabyte or Kilobyte) so all your data are at the same level, then you use a formatter to display things more properly, and the number sorter

If i take the two value i gave you for example, and considering the base value is Megabite, then the formatter would display 4.25 Mb, 10.25Gb, and 12Kb (depending on how you do the conversion)

Then, you set your size column with the number sorter, then you can use either header sorting (little arrow icon in the header) or set sorting programmatically

If you directly inject "4.25Mb" in the column, the sorting will be donne on a string value and by character comparison, so if you sort ascending 1000 wil come before 2. I'd guess that was your problem.

Hope i helped

Hi,

You are right that I fill MB or GB and the sorting is done on string. I
will look into formatter and do my sorting based on numbers.

Thanks for your help.

On Tue, Jul 25, 2017 at 11:42 AM, pmirial notifications@github.com wrote:

Hi
I would recommend you to use a numerical value (like 4.25, 10248 or 0.012)
representing the most common "scale" your data is (Megabyte, Gigabyte or
Kilobyte) so all your data are at the same level, then you use a formatter
http://olifolkerd.github.io/tabulator/docs/#formattingto display things
more properly, and the number sorter
http://olifolkerd.github.io/tabulator/docs/#sorting

If i take the two value i gave you for example, and considering the base
value is Megabite, then the formatter would display 4.25 Mb, 10.25Gb, and
12Kb (depending on how you do the conversion)

Then, you set your size column with the number sorter, then you can use
either header sorting (little arrow icon in the header) or set sorting
programmatically

If you directly inject "4.25Mb" in the column, the sorting will be donne
on a string value and by character comparison, so if you sort ascending
1000 wil come before 2. I'd guess that was your problem.

Hope i helped

—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
https://github.com/olifolkerd/tabulator/issues/477#issuecomment-317685777,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAD5ixz1sBw2GHJgDVFDMcrZAGrEeh1yks5sRbhwgaJpZM4OiP34
.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

alainpannetier picture alainpannetier  Â·  3Comments

aballeras01 picture aballeras01  Â·  3Comments

andreivanea picture andreivanea  Â·  3Comments

KES777 picture KES777  Â·  3Comments

Manbec picture Manbec  Â·  3Comments