3 This file is part of Ext JS 4
5 Copyright (c) 2011 Sencha Inc
7 Contact: http://www.sencha.com/contact
9 GNU General Public License Usage
10 This file may be used under the terms of the GNU General Public License version 3.0 as published by the Free Software Foundation and appearing in the file LICENSE included in the packaging of this file. Please review the following information to ensure the GNU General Public License version 3.0 requirements will be met: http://www.gnu.org/copyleft/gpl.html.
12 If you are unsure which license is appropriate for your use, please contact the sales department at http://www.sencha.com/contact.
16 * @class Ext.data.SortTypes
17 * This class defines a series of static methods that are used on a
18 * {@link Ext.data.Field} for performing sorting. The methods cast the
19 * underlying values into a data type that is appropriate for sorting on
20 * that particular field. If a {@link Ext.data.Field#type} is specified,
21 * the sortType will be set to a sane default if the sortType is not
22 * explicitly defined on the field. The sortType will make any necessary
23 * modifications to the value and return it.
25 * <li><b>asText</b> - Removes any tags and converts the value to a string</li>
26 * <li><b>asUCText</b> - Removes any tags and converts the value to an uppercase string</li>
27 * <li><b>asUCText</b> - Converts the value to an uppercase string</li>
28 * <li><b>asDate</b> - Converts the value into Unix epoch time</li>
29 * <li><b>asFloat</b> - Converts the value to a floating point number</li>
30 * <li><b>asInt</b> - Converts the value to an integer number</li>
33 * It is also possible to create a custom sortType that can be used throughout
36 Ext.apply(Ext.data.SortTypes, {
37 asPerson: function(person){
38 // expects an object with a first and last name property
39 return person.lastName.toUpperCase() + person.firstName.toLowerCase();
43 Ext.define('Employee', {
44 extend: 'Ext.data.Model',
50 type: 'float' // sortType set to asFloat
56 * @docauthor Evan Trimboli <evan@sencha.com>
58 Ext.define('Ext.data.SortTypes', {
63 * Default sort that does nothing
64 * @param {Object} s The value being converted
65 * @return {Object} The comparison value
72 * The regular expression used to strip tags
76 stripTagsRE : /<\/?[^>]+>/gi,
79 * Strips all HTML tags to sort on text only
80 * @param {Object} s The value being converted
81 * @return {String} The comparison value
83 asText : function(s) {
84 return String(s).replace(this.stripTagsRE, "");
88 * Strips all HTML tags to sort on text only - Case insensitive
89 * @param {Object} s The value being converted
90 * @return {String} The comparison value
92 asUCText : function(s) {
93 return String(s).toUpperCase().replace(this.stripTagsRE, "");
97 * Case insensitive string
98 * @param {Object} s The value being converted
99 * @return {String} The comparison value
101 asUCString : function(s) {
102 return String(s).toUpperCase();
107 * @param {Object} s The value being converted
108 * @return {Number} The comparison value
110 asDate : function(s) {
117 return Date.parse(String(s));
122 * @param {Object} s The value being converted
123 * @return {Number} The comparison value
125 asFloat : function(s) {
126 var val = parseFloat(String(s).replace(/,/g, ""));
127 return isNaN(val) ? 0 : val;
132 * @param {Object} s The value being converted
133 * @return {Number} The comparison value
135 asInt : function(s) {
136 var val = parseInt(String(s).replace(/,/g, ""), 10);
137 return isNaN(val) ? 0 : val;