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