Upgrade to ExtJS 4.0.7 - Released 10/19/2011
[extjs.git] / docs / source / SortTypes.html
1 <!DOCTYPE html>
2 <html>
3 <head>
4   <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5   <title>The source code</title>
6   <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
7   <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
8   <style type="text/css">
9     .highlight { display: block; background-color: #ddd; }
10   </style>
11   <script type="text/javascript">
12     function highlight() {
13       document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
14     }
15   </script>
16 </head>
17 <body onload="prettyPrint(); highlight();">
18   <pre class="prettyprint lang-js"><span id='Ext-data-SortTypes'>/**
19 </span> * @class Ext.data.SortTypes
20  * This class defines a series of static methods that are used on a
21  * {@link Ext.data.Field} for performing sorting. The methods cast the 
22  * underlying values into a data type that is appropriate for sorting on
23  * that particular field.  If a {@link Ext.data.Field#type} is specified, 
24  * the sortType will be set to a sane default if the sortType is not 
25  * explicitly defined on the field. The sortType will make any necessary
26  * modifications to the value and return it.
27  * &lt;ul&gt;
28  * &lt;li&gt;&lt;b&gt;asText&lt;/b&gt; - Removes any tags and converts the value to a string&lt;/li&gt;
29  * &lt;li&gt;&lt;b&gt;asUCText&lt;/b&gt; - Removes any tags and converts the value to an uppercase string&lt;/li&gt;
30  * &lt;li&gt;&lt;b&gt;asUCText&lt;/b&gt; - Converts the value to an uppercase string&lt;/li&gt;
31  * &lt;li&gt;&lt;b&gt;asDate&lt;/b&gt; - Converts the value into Unix epoch time&lt;/li&gt;
32  * &lt;li&gt;&lt;b&gt;asFloat&lt;/b&gt; - Converts the value to a floating point number&lt;/li&gt;
33  * &lt;li&gt;&lt;b&gt;asInt&lt;/b&gt; - Converts the value to an integer number&lt;/li&gt;
34  * &lt;/ul&gt;
35  * &lt;p&gt;
36  * It is also possible to create a custom sortType that can be used throughout
37  * an application.
38  * &lt;pre&gt;&lt;code&gt;
39 Ext.apply(Ext.data.SortTypes, {
40     asPerson: function(person){
41         // expects an object with a first and last name property
42         return person.lastName.toUpperCase() + person.firstName.toLowerCase();
43     }    
44 });
45
46 Ext.define('Employee', {
47     extend: 'Ext.data.Model',
48     fields: [{
49         name: 'person',
50         sortType: 'asPerson'
51     }, {
52         name: 'salary',
53         type: 'float' // sortType set to asFloat
54     }]
55 });
56  * &lt;/code&gt;&lt;/pre&gt;
57  * &lt;/p&gt;
58  * @singleton
59  * @docauthor Evan Trimboli &lt;evan@sencha.com&gt;
60  */
61 Ext.define('Ext.data.SortTypes', {
62     
63     singleton: true,
64     
65 <span id='Ext-data-SortTypes-method-none'>    /**
66 </span>     * Default sort that does nothing
67      * @param {Object} s The value being converted
68      * @return {Object} The comparison value
69      */
70     none : function(s) {
71         return s;
72     },
73
74 <span id='Ext-data-SortTypes-property-stripTagsRE'>    /**
75 </span>     * The regular expression used to strip tags
76      * @type {RegExp}
77      * @property
78      */
79     stripTagsRE : /&lt;\/?[^&gt;]+&gt;/gi,
80
81 <span id='Ext-data-SortTypes-method-asText'>    /**
82 </span>     * Strips all HTML tags to sort on text only
83      * @param {Object} s The value being converted
84      * @return {String} The comparison value
85      */
86     asText : function(s) {
87         return String(s).replace(this.stripTagsRE, &quot;&quot;);
88     },
89
90 <span id='Ext-data-SortTypes-method-asUCText'>    /**
91 </span>     * Strips all HTML tags to sort on text only - Case insensitive
92      * @param {Object} s The value being converted
93      * @return {String} The comparison value
94      */
95     asUCText : function(s) {
96         return String(s).toUpperCase().replace(this.stripTagsRE, &quot;&quot;);
97     },
98
99 <span id='Ext-data-SortTypes-method-asUCString'>    /**
100 </span>     * Case insensitive string
101      * @param {Object} s The value being converted
102      * @return {String} The comparison value
103      */
104     asUCString : function(s) {
105         return String(s).toUpperCase();
106     },
107
108 <span id='Ext-data-SortTypes-method-asDate'>    /**
109 </span>     * Date sorting
110      * @param {Object} s The value being converted
111      * @return {Number} The comparison value
112      */
113     asDate : function(s) {
114         if(!s){
115             return 0;
116         }
117         if(Ext.isDate(s)){
118             return s.getTime();
119         }
120         return Date.parse(String(s));
121     },
122
123 <span id='Ext-data-SortTypes-method-asFloat'>    /**
124 </span>     * Float sorting
125      * @param {Object} s The value being converted
126      * @return {Number} The comparison value
127      */
128     asFloat : function(s) {
129         var val = parseFloat(String(s).replace(/,/g, &quot;&quot;));
130         return isNaN(val) ? 0 : val;
131     },
132
133 <span id='Ext-data-SortTypes-method-asInt'>    /**
134 </span>     * Integer sorting
135      * @param {Object} s The value being converted
136      * @return {Number} The comparison value
137      */
138     asInt : function(s) {
139         var val = parseInt(String(s).replace(/,/g, &quot;&quot;), 10);
140         return isNaN(val) ? 0 : val;
141     }
142 });</pre>
143 </body>
144 </html>