Issue:
There's some unexpected behavior occuring within the table sorting
functionality, as performed by the sortByColumn function within
SimpleTableModel.js.  The sort is currently case sensitive, which is
probably not intended.  

For instance, if 
a
B
c

is sorted in descending order, it returns 
c
a
B

I believe the preferred behavior within most applications would be
c
B
a

Root Cause:
The root cause is that javascript, of course, is case sensitive.  Thus, the
sort routine must know to deal with case prior to evaluating values for
purposes of sorting.  This functionality is housed within the sortByColumn
function within SimpleTableModel.js.

Solution:
Within sortByColumn function within SimpleTableModel.js, set obj1 and obj2
to lowercase values:

Before:

      if (ascending)
      {
        comperator = function(row1, row2)
        {
          var obj1 = row1[columnIndex];
          var obj2 = row2[columnIndex];
          return (obj1 > obj2) ? 1 : ((obj1 == obj2) ? 0 : -1);
        };
      }
      else
      {
        comperator = function(row1, row2)
        {
          var obj1 = row1[columnIndex];
          var obj2 = row2[columnIndex];
          return (obj1 < obj2) ? 1 : ((obj1 == obj2) ? 0 : -1);
        };
      }

After:

  if (ascending) {
    comperator = function(row1, row2) {
          var obj1 = row1[columnIndex];
          var obj2 = row2[columnIndex];
          if (typeof(obj1) != "number" && typeof(obj2) != "number"){
            obj1 = row1[columnIndex].toLowerCase();
            obj2 = row2[columnIndex].toLowerCase();     
          }
      return (obj1 > obj2) ? 1 : ((obj1 == obj2) ? 0 : -1);
    };
  } else {
    comperator = function(row1, row2) {
          var obj1 = row1[columnIndex];
          var obj2 = row2[columnIndex];
          if (typeof(obj1) != "number" && typeof(obj2) != "number"){
                obj1 = row1[columnIndex].toLowerCase();
                obj2 = row2[columnIndex].toLowerCase(); 
          }
      return (obj1 < obj2) ? 1 : ((obj1 == obj2) ? 0 : -1);
    };
  }

I'm sort of a monkey with a chainsaw when it comes to hardcore javascript,
so I hope the code I changed is up to qooxdoo standards.  It would cool if
this change could be added to the 0.7 alpha.

Note, the if (typeof(obj1) != "number" && typeof(obj2) != "number"){} code
is needed so that numeric fields still work.  They'll break if we try to
apply .toLowerCase to them.

Thanks!

-Mike
-- 
View this message in context: 
http://www.nabble.com/Table-Sorting-Issue---Resolution-for-0.7-alpha.-tf3756306.html#a10616537
Sent from the qooxdoo-devel mailing list archive at Nabble.com.


-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
qooxdoo-devel mailing list
qooxdoo-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel

Reply via email to