4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5 <title>The source code</title>
6 <link href="../prettify/prettify.css" type="text/css" rel="stylesheet" />
7 <script type="text/javascript" src="../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-Types'>/**
19 </span> * @class Ext.data.Types
20 * <p>This is s static class containing the system-supplied data types which may be given to a {@link Ext.data.Field Field}.<p/>
21 * <p>The properties in this class are used as type indicators in the {@link Ext.data.Field Field} class, so to
22 * test whether a Field is of a certain type, compare the {@link Ext.data.Field#type type} property against properties
23 * of this class.</p>
24 * <p>Developers may add their own application-specific data types to this class. Definition names must be UPPERCASE.
25 * each type definition must contain three properties:</p>
26 * <div class="mdetail-params"><ul>
27 * <li><code>convert</code> : <i>Function</i><div class="sub-desc">A function to convert raw data values from a data block into the data
28 * to be stored in the Field. The function is passed the collowing parameters:
29 * <div class="mdetail-params"><ul>
30 * <li><b>v</b> : Mixed<div class="sub-desc">The data value as read by the Reader, if undefined will use
31 * the configured <tt>{@link Ext.data.Field#defaultValue defaultValue}</tt>.</div></li>
32 * <li><b>rec</b> : Mixed<div class="sub-desc">The data object containing the row as read by the Reader.
33 * Depending on the Reader type, this could be an Array ({@link Ext.data.reader.Array ArrayReader}), an object
34 * ({@link Ext.data.reader.Json JsonReader}), or an XML element.</div></li>
35 * </ul></div></div></li>
36 * <li><code>sortType</code> : <i>Function</i> <div class="sub-desc">A function to convert the stored data into comparable form, as defined by {@link Ext.data.SortTypes}.</div></li>
37 * <li><code>type</code> : <i>String</i> <div class="sub-desc">A textual data type name.</div></li>
38 * </ul></div>
39 * <p>For example, to create a VELatLong field (See the Microsoft Bing Mapping API) containing the latitude/longitude value of a datapoint on a map from a JsonReader data block
40 * which contained the properties <code>lat</code> and <code>long</code>, you would define a new data type like this:</p>
41 *<pre><code>
42 // Add a new Field data type which stores a VELatLong object in the Record.
43 Ext.data.Types.VELATLONG = {
44 convert: function(v, data) {
45 return new VELatLong(data.lat, data.long);
47 sortType: function(v) {
48 return v.Latitude; // When sorting, order by latitude
52 </code></pre>
53 * <p>Then, when declaring a Model, use <pre><code>
54 var types = Ext.data.Types; // allow shorthand type access
56 extend: 'Ext.data.Model',
58 { name: 'unitName', mapping: 'UnitName' },
59 { name: 'curSpeed', mapping: 'CurSpeed', type: types.INT },
60 { name: 'latitude', mapping: 'lat', type: types.FLOAT },
61 { name: 'latitude', mapping: 'lat', type: types.FLOAT },
62 { name: 'position', type: types.VELATLONG }
65 </code></pre>
68 Ext.define('Ext.data.Types', {
70 requires: ['Ext.data.SortTypes']
72 var st = Ext.data.SortTypes;
74 Ext.apply(Ext.data.Types, {
75 <span id='Ext-data-Types-property-stripRe'> /**
76 </span> * @type Regexp
78 * A regular expression for stripping non-numeric characters from a numeric value. Defaults to <tt>/[\$,%]/g</tt>.
79 * This should be overridden for localization.
83 <span id='Ext-data-Types-property-AUTO'> /**
84 </span> * @type Object.
86 * This data type means that no conversion is applied to the raw data before it is placed into a Record.
89 convert: function(v) {
96 <span id='Ext-data-Types-property-STRING'> /**
97 </span> * @type Object.
99 * This data type means that the raw data is converted into a String before it is placed into a Record.
102 convert: function(v) {
103 var defaultValue = this.useNull ? null : '';
104 return (v === undefined || v === null) ? defaultValue : String(v);
106 sortType: st.asUCString,
110 <span id='Ext-data-Types-property-INT'> /**
111 </span> * @type Object.
113 * This data type means that the raw data is converted into an integer before it is placed into a Record.
114 * <p>The synonym <code>INTEGER</code> is equivalent.</p>
117 convert: function(v) {
118 return v !== undefined && v !== null && v !== '' ?
119 parseInt(String(v).replace(Ext.data.Types.stripRe, ''), 10) : (this.useNull ? null : 0);
125 <span id='Ext-data-Types-property-FLOAT'> /**
126 </span> * @type Object.
128 * This data type means that the raw data is converted into a number before it is placed into a Record.
129 * <p>The synonym <code>NUMBER</code> is equivalent.</p>
132 convert: function(v) {
133 return v !== undefined && v !== null && v !== '' ?
134 parseFloat(String(v).replace(Ext.data.Types.stripRe, ''), 10) : (this.useNull ? null : 0);
140 <span id='Ext-data-Types-property-BOOL'> /**
141 </span> * @type Object.
143 * <p>This data type means that the raw data is converted into a boolean before it is placed into
144 * a Record. The string "true" and the number 1 are converted to boolean <code>true</code>.</p>
145 * <p>The synonym <code>BOOLEAN</code> is equivalent.</p>
148 convert: function(v) {
149 if (this.useNull && v === undefined || v === null || v === '') {
152 return v === true || v === 'true' || v == 1;
158 <span id='Ext-data-Types-property-DATE'> /**
159 </span> * @type Object.
161 * This data type means that the raw data is converted into a Date before it is placed into a Record.
162 * The date format is specified in the constructor of the {@link Ext.data.Field} to which this type is
166 convert: function(v) {
167 var df = this.dateFormat;
175 if (df == 'timestamp') {
176 return new Date(v*1000);
179 return new Date(parseInt(v, 10));
181 return Ext.Date.parse(v, df);
184 var parsed = Date.parse(v);
185 return parsed ? new Date(parsed) : null;
192 Ext.apply(Ext.data.Types, {
193 <span id='Ext-data-Types-property-BOOLEAN'> /**
194 </span> * @type Object.
196 * <p>This data type means that the raw data is converted into a boolean before it is placed into
197 * a Record. The string "true" and the number 1 are converted to boolean <code>true</code>.</p>
198 * <p>The synonym <code>BOOL</code> is equivalent.</p>
202 <span id='Ext-data-Types-property-INTEGER'> /**
203 </span> * @type Object.
205 * This data type means that the raw data is converted into an integer before it is placed into a Record.
206 * <p>The synonym <code>INT</code> is equivalent.</p>
210 <span id='Ext-data-Types-property-NUMBER'> /**
211 </span> * @type Object.
213 * This data type means that the raw data is converted into a number before it is placed into a Record.
214 * <p>The synonym <code>FLOAT</code> is equivalent.</p>