2 * @class Ext.data.SortTypes
3 * This class defines a series of static methods that are used on a
4 * {@link Ext.data.Field} for performing sorting. The methods cast the
5 * underlying values into a data type that is appropriate for sorting on
6 * that particular field. If a {@link Ext.data.Field#type} is specified,
7 * the sortType will be set to a sane default if the sortType is not
8 * explicitly defined on the field. The sortType will make any necessary
9 * modifications to the value and return it.
11 * <li><b>asText</b> - Removes any tags and converts the value to a string</li>
12 * <li><b>asUCText</b> - Removes any tags and converts the value to an uppercase string</li>
13 * <li><b>asUCText</b> - Converts the value to an uppercase string</li>
14 * <li><b>asDate</b> - Converts the value into Unix epoch time</li>
15 * <li><b>asFloat</b> - Converts the value to a floating point number</li>
16 * <li><b>asInt</b> - Converts the value to an integer number</li>
19 * It is also possible to create a custom sortType that can be used throughout
22 Ext.apply(Ext.data.SortTypes, {
23 asPerson: function(person){
24 // expects an object with a first and last name property
25 return person.lastName.toUpperCase() + person.firstName.toLowerCase();
29 Ext.define('Employee', {
30 extend: 'Ext.data.Model',
36 type: 'float' // sortType set to asFloat
42 * @docauthor Evan Trimboli <evan@sencha.com>
44 Ext.define('Ext.data.SortTypes', {
49 * Default sort that does nothing
50 * @param {Mixed} s The value being converted
51 * @return {Mixed} The comparison value
58 * The regular expression used to strip tags
62 stripTagsRE : /<\/?[^>]+>/gi,
65 * Strips all HTML tags to sort on text only
66 * @param {Mixed} s The value being converted
67 * @return {String} The comparison value
69 asText : function(s) {
70 return String(s).replace(this.stripTagsRE, "");
74 * Strips all HTML tags to sort on text only - Case insensitive
75 * @param {Mixed} s The value being converted
76 * @return {String} The comparison value
78 asUCText : function(s) {
79 return String(s).toUpperCase().replace(this.stripTagsRE, "");
83 * Case insensitive string
84 * @param {Mixed} s The value being converted
85 * @return {String} The comparison value
87 asUCString : function(s) {
88 return String(s).toUpperCase();
93 * @param {Mixed} s The value being converted
94 * @return {Number} The comparison value
96 asDate : function(s) {
103 return Date.parse(String(s));
108 * @param {Mixed} s The value being converted
109 * @return {Float} The comparison value
111 asFloat : function(s) {
112 var val = parseFloat(String(s).replace(/,/g, ""));
113 return isNaN(val) ? 0 : val;
118 * @param {Mixed} s The value being converted
119 * @return {Number} The comparison value
121 asInt : function(s) {
122 var val = parseInt(String(s).replace(/,/g, ""), 10);
123 return isNaN(val) ? 0 : val;