Upgrade to ExtJS 4.0.0 - Released 04/26/2011
[extjs.git] / src / data / SortTypes.js
index 9267b04..0f52038 100644 (file)
-/*!
- * Ext JS Library 3.0.3
- * Copyright(c) 2006-2009 Ext JS, LLC
- * licensing@extjs.com
- * http://www.extjs.com/license
+/**
+ * @class Ext.data.SortTypes
+ * This class defines a series of static methods that are used on a
+ * {@link Ext.data.Field} for performing sorting. The methods cast the 
+ * underlying values into a data type that is appropriate for sorting on
+ * that particular field.  If a {@link Ext.data.Field#type} is specified, 
+ * the sortType will be set to a sane default if the sortType is not 
+ * explicitly defined on the field. The sortType will make any necessary
+ * modifications to the value and return it.
+ * <ul>
+ * <li><b>asText</b> - Removes any tags and converts the value to a string</li>
+ * <li><b>asUCText</b> - Removes any tags and converts the value to an uppercase string</li>
+ * <li><b>asUCText</b> - Converts the value to an uppercase string</li>
+ * <li><b>asDate</b> - Converts the value into Unix epoch time</li>
+ * <li><b>asFloat</b> - Converts the value to a floating point number</li>
+ * <li><b>asInt</b> - Converts the value to an integer number</li>
+ * </ul>
+ * <p>
+ * It is also possible to create a custom sortType that can be used throughout
+ * an application.
+ * <pre><code>
+Ext.apply(Ext.data.SortTypes, {
+    asPerson: function(person){
+        // expects an object with a first and last name property
+        return person.lastName.toUpperCase() + person.firstName.toLowerCase();
+    }    
+});
+
+Ext.define('Employee', {
+    extend: 'Ext.data.Model',
+    fields: [{
+        name: 'person',
+        sortType: 'asPerson'
+    }, {
+        name: 'salary',
+        type: 'float' // sortType set to asFloat
+    }]
+});
+ * </code></pre>
+ * </p>
+ * @singleton
+ * @docauthor Evan Trimboli <evan@sencha.com>
  */
-\r
-/**\r
- * @class Ext.data.SortTypes\r
- * @singleton\r
- * Defines the default sorting (casting?) comparison functions used when sorting data.\r
- */\r
-Ext.data.SortTypes = {\r
-    /**\r
-     * Default sort that does nothing\r
-     * @param {Mixed} s The value being converted\r
-     * @return {Mixed} The comparison value\r
-     */\r
-    none : function(s){\r
-        return s;\r
-    },\r
-    \r
-    /**\r
-     * The regular expression used to strip tags\r
-     * @type {RegExp}\r
-     * @property\r
-     */\r
-    stripTagsRE : /<\/?[^>]+>/gi,\r
-    \r
-    /**\r
-     * Strips all HTML tags to sort on text only\r
-     * @param {Mixed} s The value being converted\r
-     * @return {String} The comparison value\r
-     */\r
-    asText : function(s){\r
-        return String(s).replace(this.stripTagsRE, "");\r
-    },\r
-    \r
-    /**\r
-     * Strips all HTML tags to sort on text only - Case insensitive\r
-     * @param {Mixed} s The value being converted\r
-     * @return {String} The comparison value\r
-     */\r
-    asUCText : function(s){\r
-        return String(s).toUpperCase().replace(this.stripTagsRE, "");\r
-    },\r
-    \r
-    /**\r
-     * Case insensitive string\r
-     * @param {Mixed} s The value being converted\r
-     * @return {String} The comparison value\r
-     */\r
-    asUCString : function(s) {\r
-       return String(s).toUpperCase();\r
-    },\r
-    \r
-    /**\r
-     * Date sorting\r
-     * @param {Mixed} s The value being converted\r
-     * @return {Number} The comparison value\r
-     */\r
-    asDate : function(s) {\r
-        if(!s){\r
-            return 0;\r
-        }\r
-        if(Ext.isDate(s)){\r
-            return s.getTime();\r
-        }\r
-       return Date.parse(String(s));\r
-    },\r
-    \r
-    /**\r
-     * Float sorting\r
-     * @param {Mixed} s The value being converted\r
-     * @return {Float} The comparison value\r
-     */\r
-    asFloat : function(s) {\r
-       var val = parseFloat(String(s).replace(/,/g, ""));\r
-       return isNaN(val) ? 0 : val;\r
-    },\r
-    \r
-    /**\r
-     * Integer sorting\r
-     * @param {Mixed} s The value being converted\r
-     * @return {Number} The comparison value\r
-     */\r
-    asInt : function(s) {\r
-        var val = parseInt(String(s).replace(/,/g, ""), 10);\r
-        return isNaN(val) ? 0 : val;\r
-    }\r
-};
\ No newline at end of file
+Ext.define('Ext.data.SortTypes', {
+    
+    singleton: true,
+    
+    /**
+     * Default sort that does nothing
+     * @param {Mixed} s The value being converted
+     * @return {Mixed} The comparison value
+     */
+    none : function(s) {
+        return s;
+    },
+
+    /**
+     * The regular expression used to strip tags
+     * @type {RegExp}
+     * @property
+     */
+    stripTagsRE : /<\/?[^>]+>/gi,
+
+    /**
+     * Strips all HTML tags to sort on text only
+     * @param {Mixed} s The value being converted
+     * @return {String} The comparison value
+     */
+    asText : function(s) {
+        return String(s).replace(this.stripTagsRE, "");
+    },
+
+    /**
+     * Strips all HTML tags to sort on text only - Case insensitive
+     * @param {Mixed} s The value being converted
+     * @return {String} The comparison value
+     */
+    asUCText : function(s) {
+        return String(s).toUpperCase().replace(this.stripTagsRE, "");
+    },
+
+    /**
+     * Case insensitive string
+     * @param {Mixed} s The value being converted
+     * @return {String} The comparison value
+     */
+    asUCString : function(s) {
+        return String(s).toUpperCase();
+    },
+
+    /**
+     * Date sorting
+     * @param {Mixed} s The value being converted
+     * @return {Number} The comparison value
+     */
+    asDate : function(s) {
+        if(!s){
+            return 0;
+        }
+        if(Ext.isDate(s)){
+            return s.getTime();
+        }
+        return Date.parse(String(s));
+    },
+
+    /**
+     * Float sorting
+     * @param {Mixed} s The value being converted
+     * @return {Float} The comparison value
+     */
+    asFloat : function(s) {
+        var val = parseFloat(String(s).replace(/,/g, ""));
+        return isNaN(val) ? 0 : val;
+    },
+
+    /**
+     * Integer sorting
+     * @param {Mixed} s The value being converted
+     * @return {Number} The comparison value
+     */
+    asInt : function(s) {
+        var val = parseInt(String(s).replace(/,/g, ""), 10);
+        return isNaN(val) ? 0 : val;
+    }
+});
\ No newline at end of file