Page MenuHomePhabricator

Tablesorter should sort 'invalid' values alphabetically ("natural sorting")
Open, LowPublic

Description

Example:

{| class="wikitable sortable"
|-
! data-sort-type="number" | Number of foos
|-
| 2
|-
| unknown
|-
| 5
|-
| N/A
|-
| 1
|-
| 0
|-
| N/A
|-
| unknown
|}

This currently sorts as:

unknown
N/A
0
N/A
unknown
1
2
5

while the expected order is

N/A
N/A
unknown
unknown
0
1
2
5

I.e: When the sort type is numerical, the function used for comparison should sort

  • two numbers according to their value
  • any number (including 0 and negative numbers) after any non-number
  • two non-numbers according to their position in alphabet

Version: 1.23.0
Severity: enhancement

Details

Reference
bz58443

Event Timeline

bzimport raised the priority of this task from to Low.Nov 22 2014, 2:20 AM
bzimport set Reference to bz58443.
bzimport added a subscriber: Unknown Object (MLST).

I'm pretty sure what you described is called "natural sorting" (identifying runs of digits and non-digits and sorting them separately –
http://www.codinghorror.com/blog/2007/12/sorting-for-humans-natural-sort-order.html), and something I would love to implement some day.

(Somewhat related: bug 45161.)

TheDJ renamed this task from Tablesorter should sort non-numerical values alphabeticaly ("natural sorting") to Tablesorter should sort 'invalid' values alphabeticaly ("natural sorting").Jun 15 2020, 11:29 AM
TheDJ renamed this task from Tablesorter should sort 'invalid' values alphabeticaly ("natural sorting") to Tablesorter should sort 'invalid' values alphabetically ("natural sorting").
TheDJ updated the task description. (Show Details)

This would require redoing the sort value formatting. Currently all numeric is formatted with formatDigit and then assigned -Infinity if it is not a number, before being sorted. In order to keep natural sorting here would require applying natural sort on the remaining items that now share -Infinity. Bit hard to do as we just 'removed' that information in the previous step.

Possibly return tuples from formatDigit instead ? Or convert numericSorting to localcompare sorting as well ? Not sure how localeCompare handles non-latin numbers and things like −