Fabian:

Here goes the patch against legacy_legacy_0_7_x. It should apply cleanly
to qx/ui/table/model/Simple.js

The provided funcionality is insensitive sorting in the Simple Table
Model. Example:

  var tableModel = new qx.ui.table.model.Simple();
  tableModel.setCaseInsensitiveSorting(true);

should do the trick.. The code is based on what was provided by Stefan.


Best regards. Raul


On Wed, 2007-11-28 at 09:37 +0100, Fabian Jakobs wrote:
> Raul Gutierrez S. schrieb:
> > On Thu, 2007-11-22 at 15:01 +0100, Fa. Linstep, Stefan Volbers wrote:
> >   
> >> Hi Tobias,
> >>
> >> within qooxdoo0.6.6, I helped myself by overriding qx.Proto.sortByColumn
> >> in a custom sorting table model which is derived from 
> >> qx.ui.table.SimpleTableModel, like that:
> >>     
> >
> > This is pretty interesting.. It would be nice to have this functionality
> > on 0.7 via something like tableModel.setCaseInsensitiveSorting(true).
> >
> > I could make a patch, using this code, if it would have a chance of 
> > being pushed in.
> >
> >   
> I would really appreciate a patch. I think this is a useful extension.
> 
> 
> Best Fabian
> 
-- 
---------------------------
     Raúl Gutierrez S.
 Investigación y Desarrollo
   Taller de Ideas S.A. 
Index: Simple.js
===================================================================
--- Simple.js	(revision 10849)
+++ Simple.js	(working copy)
@@ -45,6 +45,15 @@
     this._editableColArr = null;
   },
 
+  properties :
+  {
+    caseInsensitiveSorting :
+    {
+      check    : "Boolean",
+      init : false
+    }
+  },
+      
 
   statics :
   {
@@ -64,7 +73,26 @@
         return (obj1 > obj2) ? 1 : ((obj1 == obj2) ? 0 : -1);
       },
 
+
     /**
+     * Same as the Default ascending sort method but using case insensitivity 
+     * 
+     * @param row1 {var} first row
+     * @param row2 {var} second row
+     * @return {Integer} 1 of row1 is > row2, -1 if row1 is < row2, 0 if row1 == row2
+     */
+      _defaultSortComparatorInsensitiveAscending :
+	function(row1, row2) 
+	{
+	  var obj1 = (isNaN(row1[arguments.callee.columnIndex]) ? 
+		      row1[arguments.callee.columnIndex].toLowerCase() : row1[arguments.callee.columnIndex]); 
+	  var obj2 = (isNaN(row2[arguments.callee.columnIndex]) ? 
+		      row2[arguments.callee.columnIndex].toLowerCase() : row2[arguments.callee.columnIndex]);
+	  return (obj1 > obj2) ? 1 : ((obj1 == obj2) ? 0 : -1);
+	},
+
+
+    /**
      * Default descendeing sort method to use if no custom method has been
      * provided.
      *
@@ -78,7 +106,26 @@
         var obj1 = row1[arguments.callee.columnIndex];
         var obj2 = row2[arguments.callee.columnIndex];
         return (obj1 < obj2) ? 1 : ((obj1 == obj2) ? 0 : -1);
+      },
+
+
+    /**
+     * Same as the Default descending sort method but using case insensitivity 
+     * 
+     * @param row1 {var} first row
+     * @param row2 {var} second row
+     * @return {Integer} 1 of row1 is > row2, -1 if row1 is < row2, 0 if row1 == row2
+     */
+      _defaultSortComparatorInsensitiveDescending :
+      function(row1, row2)
+      {
+	var obj1 = (isNaN(row1[arguments.callee.columnIndex]) ? 
+		    row1[arguments.callee.columnIndex].toLowerCase() : row1[arguments.callee.columnIndex]);
+	var obj2 = (isNaN(row2[arguments.callee.columnIndex]) ? 
+		    row2[arguments.callee.columnIndex].toLowerCase() : row2[arguments.callee.columnIndex]);
+	return (obj1 < obj2) ? 1 : ((obj1 == obj2) ? 0 : -1);
       }
+
   },
 
 
@@ -206,10 +253,17 @@
       }
       else
       {
-        comparator =
-          (ascending
-           ? qx.ui.table.model.Simple._defaultSortComparatorAscending
-           : qx.ui.table.model.Simple._defaultSortComparatorDescending);
+	if (this.getCaseInsensitiveSorting()) {
+	  comparator =
+	    (ascending
+	     ? qx.ui.table.model.Simple._defaultSortComparatorInsensitiveAscending
+	     : qx.ui.table.model.Simple._defaultSortComparatorInsensitiveDescending);
+	} else {
+	  comparator =
+	    (ascending
+	     ? qx.ui.table.model.Simple._defaultSortComparatorAscending
+	     : qx.ui.table.model.Simple._defaultSortComparatorDescending);
+	}
       }
 
       comparator.columnIndex = columnIndex;
-------------------------------------------------------------------------
SF.Net email is sponsored by: The Future of Linux Business White Paper
from Novell.  From the desktop to the data center, Linux is going
mainstream.  Let it simplify your IT future.
http://altfarm.mediaplex.com/ad/ck/8857-50307-18918-4
_______________________________________________
qooxdoo-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel

Reply via email to