+ NOTE! +
+-
+
- Added this parser in v2.28.6. +
- The problem with leading zeros:
+
-
+
- When using the number parser (
sorter-digit
in the first column), the leading zeros are removed upon parsing, so all equal values are sorted in a non-stable manner.
+ - Switching the parser to text (
sorter-text
in the second column) will behave the same as the number parser in the first column. This happens because the internal natural sort algorithm processes numeric values similar to the number parser.
+ - Prior to this parser, it was recommended to use a plain text sort (setting
textSorter
for the third column; see issue #409). This method is not ideal as a plain sort will sort2
after15
, and sort all leading zeros at the top of the column.
+ - This parser (
sorter-leadingZeros
in the fourth column) processes leading zeros by subtracting a very small number from the parsed value based on the total length of the string.
+
- When using the number parser (
1e-10
). If you are using higher precision values, then copy this parser and increase the precision as needed.Demo
+ +Number sort | +Natural text sort | + +Plain text sort | +Leading Zeros parser | +
---|---|---|---|
001 | 001 | 001 | 001 |
1 | 1 | 1 | 1 |
2 | 2 | 2 | 2 |
10 | 10 | 10 | 10 |
01 | 01 | 01 | 01 |
1.01 | 1.01 | 1.01 | 1.01 |
000001 | 000001 | 000001 | 000001 |
00001 | 00001 | 00001 | 00001 |
020 | 020 | 020 | 020 |
0001 | 0001 | 0001 | 0001 |
3 | 3 | 3 | 3 |
10 | 10 | 10 | 10 |
12 | 12 | 12 | 12 |
15 | 15 | 15 | 15 |
02 | 02 | 02 | 02 |
5 | 5 | 5 | 5 |
25 | 25 | 25 | 25 |
21 | 21 | 21 | 21 |
Page Header
+
+
+
+ <link href="css/theme.blue.css" rel="stylesheet"> +<script src="js/jquery.min.js"></script> +<script src="js/jquery.tablesorter.js"></script> +<script src="js/parser-leading-zeros.js"></script>+
Javascript
+
+
+
+
+ HTML
+
+
+
+
+