Sorting in tables can be allowed with the sortable-option.
Tablesorter.js [https://phabricator.wikimedia.org/diffusion/MW/browse/master/resources/src/jquery/jquery.tablesorter.js] tries to select a way of sorting if this is not specified by the writer of the code.
Tablesorter does, if (auto)-selected parser = 'number', assign a zero-value to non-numerical input (isNaN).
In a number of lists, this is an exceptable choice, in others it would be better to have the non-numerical input listed below any numerical input.
I would like to have an extra Parser, which gives a MAX_VALUE to all non-numerical input, or (even better, but I didn't figure out how) have the non-numerical values sorted below the numerical values.
A possible solution would be the adding of two functions to [https://phabricator.wikimedia.org/diffusion/MW/browse/master/resources/src/jquery/jquery.tablesorter.js]:
formatDigitnf, similar to formatDigit, but with MAX_VALUE for isNaN
<code>
formatDigitnf: function ( s ) { var out, c, p, i; if ( ts.transformTable !== false ) { out = ''; for ( p = 0; p < s.length; p++ ) { c = s.charAt( p ); if ( c in ts.transformTable ) { out += ts.transformTable[ c ]; } else { out += c; } } s = out; } i = parseFloat( s.replace( /[, ]/g, '' ).replace( '\u2212', '-' ) ); return isNaN( i ) ? MAX_VALUE : i;
},
</code>
extra Parser
<code>
ts.addParser( {
id: 'numberfirst', is: function ( s ) { return $.tablesorter.numberRegex.test( $.trim( s ) ); }, format: function ( s ) { return $.tablesorter.formatDigitnf( s ); }, type: 'numeric' } );
</code>
Examples of usage:
[https://nl.wikipedia.org/wiki/Formule_1_in_1987#Uitslagen_coureurs], having not qualified/started/finished drives below those who did finish
[https://nl.wikipedia.org/wiki/Lijst_van_Radio_2-Top_2000's] having not-noted songs below those who did get noted