source:
trunk/workshop-routing-foss4g/web/ext/src/data/SortTypes.js
@
76
Revision 76, 2.2 KB checked in by djay, 12 years ago (diff) | |
---|---|
|
Rev | Line | |
---|---|---|
[76] | 1 | /*! |
2 | * Ext JS Library 3.4.0 | |
3 | * Copyright(c) 2006-2011 Sencha Inc. | |
4 | * licensing@sencha.com | |
5 | * http://www.sencha.com/license | |
6 | */ | |
7 | ||
8 | /** | |
9 | * @class Ext.data.SortTypes | |
10 | * @singleton | |
11 | * Defines the default sorting (casting?) comparison functions used when sorting data. | |
12 | */ | |
13 | Ext.data.SortTypes = { | |
14 | /** | |
15 | * Default sort that does nothing | |
16 | * @param {Mixed} s The value being converted | |
17 | * @return {Mixed} The comparison value | |
18 | */ | |
19 | none : function(s){ | |
20 | return s; | |
21 | }, | |
22 | ||
23 | /** | |
24 | * The regular expression used to strip tags | |
25 | * @type {RegExp} | |
26 | * @property | |
27 | */ | |
28 | stripTagsRE : /<\/?[^>]+>/gi, | |
29 | ||
30 | /** | |
31 | * Strips all HTML tags to sort on text only | |
32 | * @param {Mixed} s The value being converted | |
33 | * @return {String} The comparison value | |
34 | */ | |
35 | asText : function(s){ | |
36 | return String(s).replace(this.stripTagsRE, ""); | |
37 | }, | |
38 | ||
39 | /** | |
40 | * Strips all HTML tags to sort on text only - Case insensitive | |
41 | * @param {Mixed} s The value being converted | |
42 | * @return {String} The comparison value | |
43 | */ | |
44 | asUCText : function(s){ | |
45 | return String(s).toUpperCase().replace(this.stripTagsRE, ""); | |
46 | }, | |
47 | ||
48 | /** | |
49 | * Case insensitive string | |
50 | * @param {Mixed} s The value being converted | |
51 | * @return {String} The comparison value | |
52 | */ | |
53 | asUCString : function(s) { | |
54 | return String(s).toUpperCase(); | |
55 | }, | |
56 | ||
57 | /** | |
58 | * Date sorting | |
59 | * @param {Mixed} s The value being converted | |
60 | * @return {Number} The comparison value | |
61 | */ | |
62 | asDate : function(s) { | |
63 | if(!s){ | |
64 | return 0; | |
65 | } | |
66 | if(Ext.isDate(s)){ | |
67 | return s.getTime(); | |
68 | } | |
69 | return Date.parse(String(s)); | |
70 | }, | |
71 | ||
72 | /** | |
73 | * Float sorting | |
74 | * @param {Mixed} s The value being converted | |
75 | * @return {Float} The comparison value | |
76 | */ | |
77 | asFloat : function(s) { | |
78 | var val = parseFloat(String(s).replace(/,/g, "")); | |
79 | return isNaN(val) ? 0 : val; | |
80 | }, | |
81 | ||
82 | /** | |
83 | * Integer sorting | |
84 | * @param {Mixed} s The value being converted | |
85 | * @return {Number} The comparison value | |
86 | */ | |
87 | asInt : function(s) { | |
88 | var val = parseInt(String(s).replace(/,/g, ""), 10); | |
89 | return isNaN(val) ? 0 : val; | |
90 | } | |
91 | }; |
Note: See TracBrowser
for help on using the repository browser.