1 <!DOCTYPE html><html><head><title>Sencha Documentation Project</title><link rel="stylesheet" href="../reset.css" type="text/css"><link rel="stylesheet" href="../prettify.css" type="text/css"><link rel="stylesheet" href="../prettify_sa.css" type="text/css"><script type="text/javascript" src="../prettify.js"></script></head><body onload="prettyPrint()"><pre class="prettyprint"><pre><span id='Ext-data.SortTypes'>/**
2 </span> * @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
21 * <pre><code>
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
39 * </code></pre>
42 * @docauthor Evan Trimboli <evan@sencha.com>
44 Ext.define('Ext.data.SortTypes', {
48 <span id='Ext-data.SortTypes-method-none'> /**
49 </span> * Default sort that does nothing
50 * @param {Mixed} s The value being converted
51 * @return {Mixed} The comparison value
57 <span id='Ext-data.SortTypes-property-stripTagsRE'> /**
58 </span> * The regular expression used to strip tags
62 stripTagsRE : /<\/?[^>]+>/gi,
64 <span id='Ext-data.SortTypes-method-asText'> /**
65 </span> * 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, "");
73 <span id='Ext-data.SortTypes-method-asUCText'> /**
74 </span> * 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, "");
82 <span id='Ext-data.SortTypes-method-asUCString'> /**
83 </span> * 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();
91 <span id='Ext-data.SortTypes-method-asDate'> /**
92 </span> * Date sorting
93 * @param {Mixed} s The value being converted
94 * @return {Number} The comparison value
96 asDate : function(s) {
103 return Date.parse(String(s));
106 <span id='Ext-data.SortTypes-method-asFloat'> /**
107 </span> * Float sorting
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;
116 <span id='Ext-data.SortTypes-method-asInt'> /**
117 </span> * Integer sorting
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;
125 });</pre></pre></body></html>