On Mar 13, 5:52 am, MorningZ <morni...@gmail.com> wrote:
> A custom parser would *definitely* handle this

I don't think a custom parser can "always force null data to the
bottom."

The custom parsers just normalize cell contents into "numeric" or
"text" format and that result is then sent on to the sorting routine.
This means that if you use a custom parser to set a null data  (or "*"
or "n/a") to be treated as "zzzzz" (text) or 99999999 (numeric) then
those cells will be pushed to the bottom for ASCENDING sorts. But when
a user clicks the th header again for DESCENDING sorts, then those
cells with null data will be on top.

I think the point of the original question was that when there is no
data in a cell, that cell is irrelevant/useless to any sorting, and
therefore should ALWAYS be pushed to the bottom of the column.

The only way to do that at this stage is to patch
jquery.tablesorter.js in 3 places (assuming that cells with only '-'
are the "null" ones):


      ts.addParser({
          id: /***************** choose an existing numeric parser to
edit, or create a new one **********/
          format: function(s) {
+             if(s == '-') return "0.000"; // flags this float for
sortNumeric() as string type, while type juggling will treat as zero



      function sortNumeric(a,b) {
+         if(a === '0.000') return 1;  // tests for string type set by
numeric Parser, means this cell has the '-'
+         else if(b === '0.000') return -1; // force cells with just
"-" always to bottom
          return a-b;


      function sortText(a,b) {
+         if(a == '-') return 1;
+         else if(b == '-') return -1; // force cells with just "-"
always to bottom
          return ((a < b) ? -1 : ((a > b) ? 1 : 0));


It is a bad hack, but is the best I can do to always force empty cells
or cells with no data to the bottom of the sorted column.

Reply via email to