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; }
11 <script type="text/javascript">
12 function highlight() {
13 document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
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.
28 * <li><b>asText</b> - Removes any tags and converts the value to a string</li>
29 * <li><b>asUCText</b> - Removes any tags and converts the value to an uppercase string</li>
30 * <li><b>asUCText</b> - Converts the value to an uppercase string</li>
31 * <li><b>asDate</b> - Converts the value into Unix epoch time</li>
32 * <li><b>asFloat</b> - Converts the value to a floating point number</li>
33 * <li><b>asInt</b> - Converts the value to an integer number</li>
36 * It is also possible to create a custom sortType that can be used throughout
38 * <pre><code>
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();
46 Ext.define('Employee', {
47 extend: 'Ext.data.Model',
53 type: 'float' // sortType set to asFloat
56 * </code></pre>
59 * @docauthor Evan Trimboli <evan@sencha.com>
61 Ext.define('Ext.data.SortTypes', {
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
74 <span id='Ext-data-SortTypes-property-stripTagsRE'> /**
75 </span> * The regular expression used to strip tags
79 stripTagsRE : /<\/?[^>]+>/gi,
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
86 asText : function(s) {
87 return String(s).replace(this.stripTagsRE, "");
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
95 asUCText : function(s) {
96 return String(s).toUpperCase().replace(this.stripTagsRE, "");
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
104 asUCString : function(s) {
105 return String(s).toUpperCase();
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
113 asDate : function(s) {
120 return Date.parse(String(s));
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
128 asFloat : function(s) {
129 var val = parseFloat(String(s).replace(/,/g, ""));
130 return isNaN(val) ? 0 : val;
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
138 asInt : function(s) {
139 var val = parseInt(String(s).replace(/,/g, ""), 10);
140 return isNaN(val) ? 0 : val;