# tablesorter

## Metric parser

### Flexible client-side table sorting

Back to documentation

NOTE!

- In v2.22.2,
  - Added header data-attribute `data-metric-name-full` which will contain the full base unit name, e.g. `"byte|Byte|BYTE"`. This change should allow for different capitalizations of the base unit name.
  - Added header data-attribute `data-metric-name-abbr` which will contain the abbreviated base unit name, e.g. `"b|B"`. This change also should allow for different capitalizations of the base unit name.
  - Each name is separated by a pipe, or vertical bar, ("`|`") without spaces, because it will eventually be used in a regular expression - the vertical bar signifies an "OR" operator.
  - When using these new data-attributes, the value in `data-metric-name` (now deprecated) will be ignored; eventually `data-metric-name` support will be removed.
  - These additions were made because of common misuse of abbreviated capitalization in the metric units, i.e. "kB" versus "kb". The lower case "b" is for "bit", and upper case "B" is for "byte". I am guilty of this too!
- This parser will convert numbers with metric prefixes ("Mega", "Giga", etc) into appropriate values so they are sorted correctly.
- The base name must be included in the header:
  - The base is the unit of measure, such as "byte", "meter", "liter", etc.
  - deprecated When saving the base, include both the abbreviation and full name of the base separated by a vertical bar (shift-\) `b|byte`.
  - deprecated Store this information within the header's data-attribute (`data-metric-name="b|byte"`) - this data-attribute should be considered deprecated as of v2.22.2, use `data-metric-name-full` & `data-metric-name-abbr` instead.
  - If no base information is found, it will default to `m|meter`.
- Because metric prefixes can be applied to binary values, the parser will calculate the cached value based on the binary multiple, i.e. `"1 kB"` is actually `"1024 bytes"`. See this article for more details.
- This parser does not (yet) support the IEC recommendations for binary prefixes (i.e. "kibibyte (KiB)", "mebibyte (MiB)", etc).
- Supported prefixes include: Yotta (1024), Zetta (1021), Exa (1018), Peta (1015), Tera (1012), Giga (109), Mega (106), kilo (103), hecto (102), deka (101), deci (10-1), centi (10-2), milli (10-3), micro (10-6), nano (10-9), pico (10-12), femto (10-15), atto (10-18), zepto (10-21) and yocto (10-24).
- This demo includes the stored metric values within the table cells, toggle the view using the button below.

# Demo

Metric (binary) Size | Metric Length
--- | ---
1 byte | 1 nm
1 kB | 1 kilometer
1 Gigabyte | 1 Gm
10 MB | 1 Tm
1 MB | 1,000 mm
1 TB | 1 meter
1 Petabyte | 1 hm
1 ZB | 1 dam
1 ZettaB | 1 millimeter
1,025 MB | 1 Mm
1,000 kilobytes | 1 dm
1 EB | 1 µm
1023 MB | 1 pm

# Page Header

    <!-- blue theme stylesheet with additional css styles added in v2.0.17 -->
    <link rel="stylesheet" href="../css/theme.blue.css">
    <!-- tablesorter plugin -->
    <script src="../js/jquery.tablesorter.js"></script>

    <!-- load metric parser -->
    <script src="../js/parsers/parser-metric.js"></script>

# Javascript

# HTML

Next up: Applying the filter widget ››