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.Types'>/**
2 </span> * @class Ext.data.Types
3 * <p>This is s static class containing the system-supplied data types which may be given to a {@link Ext.data.Field Field}.<p/>
4 * <p>The properties in this class are used as type indicators in the {@link Ext.data.Field Field} class, so to
5 * test whether a Field is of a certain type, compare the {@link Ext.data.Field#type type} property against properties
6 * of this class.</p>
7 * <p>Developers may add their own application-specific data types to this class. Definition names must be UPPERCASE.
8 * each type definition must contain three properties:</p>
9 * <div class="mdetail-params"><ul>
10 * <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
11 * to be stored in the Field. The function is passed the collowing parameters:
12 * <div class="mdetail-params"><ul>
13 * <li><b>v</b> : Mixed<div class="sub-desc">The data value as read by the Reader, if undefined will use
14 * the configured <tt>{@link Ext.data.Field#defaultValue defaultValue}</tt>.</div></li>
15 * <li><b>rec</b> : Mixed<div class="sub-desc">The data object containing the row as read by the Reader.
16 * Depending on the Reader type, this could be an Array ({@link Ext.data.reader.Array ArrayReader}), an object
17 * ({@link Ext.data.reader.Json JsonReader}), or an XML element.</div></li>
18 * </ul></div></div></li>
19 * <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>
20 * <li><code>type</code> : <i>String</i> <div class="sub-desc">A textual data type name.</div></li>
21 * </ul></div>
22 * <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
23 * which contained the properties <code>lat</code> and <code>long</code>, you would define a new data type like this:</p>
24 *<pre><code>
25 // Add a new Field data type which stores a VELatLong object in the Record.
26 Ext.data.Types.VELATLONG = {
27 convert: function(v, data) {
28 return new VELatLong(data.lat, data.long);
30 sortType: function(v) {
31 return v.Latitude; // When sorting, order by latitude
35 </code></pre>
36 * <p>Then, when declaring a Model, use <pre><code>
37 var types = Ext.data.Types; // allow shorthand type access
39 extend: 'Ext.data.Model',
41 { name: 'unitName', mapping: 'UnitName' },
42 { name: 'curSpeed', mapping: 'CurSpeed', type: types.INT },
43 { name: 'latitude', mapping: 'lat', type: types.FLOAT },
44 { name: 'latitude', mapping: 'lat', type: types.FLOAT },
45 { name: 'position', type: types.VELATLONG }
48 </code></pre>
51 Ext.define('Ext.data.Types', {
53 requires: ['Ext.data.SortTypes']
55 var st = Ext.data.SortTypes;
57 Ext.apply(Ext.data.Types, {
58 <span id='Ext-data.Types-property-stripRe'> /**
59 </span> * @type Regexp
61 * A regular expression for stripping non-numeric characters from a numeric value. Defaults to <tt>/[\$,%]/g</tt>.
62 * This should be overridden for localization.
66 <span id='Ext-data.Types-property-AUTO'> /**
67 </span> * @type Object.
69 * This data type means that no conversion is applied to the raw data before it is placed into a Record.
72 convert: function(v) {
79 <span id='Ext-data.Types-property-STRING'> /**
80 </span> * @type Object.
82 * This data type means that the raw data is converted into a String before it is placed into a Record.
85 convert: function(v) {
86 var defaultValue = this.useNull ? null : '';
87 return (v === undefined || v === null) ? defaultValue : String(v);
89 sortType: st.asUCString,
93 <span id='Ext-data.Types-property-INT'> /**
94 </span> * @type Object.
96 * This data type means that the raw data is converted into an integer before it is placed into a Record.
97 * <p>The synonym <code>INTEGER</code> is equivalent.</p>
100 convert: function(v) {
101 return v !== undefined && v !== null && v !== '' ?
102 parseInt(String(v).replace(Ext.data.Types.stripRe, ''), 10) : (this.useNull ? null : 0);
108 <span id='Ext-data.Types-property-FLOAT'> /**
109 </span> * @type Object.
111 * This data type means that the raw data is converted into a number before it is placed into a Record.
112 * <p>The synonym <code>NUMBER</code> is equivalent.</p>
115 convert: function(v) {
116 return v !== undefined && v !== null && v !== '' ?
117 parseFloat(String(v).replace(Ext.data.Types.stripRe, ''), 10) : (this.useNull ? null : 0);
123 <span id='Ext-data.Types-property-BOOL'> /**
124 </span> * @type Object.
126 * <p>This data type means that the raw data is converted into a boolean before it is placed into
127 * a Record. The string "true" and the number 1 are converted to boolean <code>true</code>.</p>
128 * <p>The synonym <code>BOOLEAN</code> is equivalent.</p>
131 convert: function(v) {
132 if (this.useNull && v === undefined || v === null || v === '') {
135 return v === true || v === 'true' || v == 1;
141 <span id='Ext-data.Types-property-DATE'> /**
142 </span> * @type Object.
144 * This data type means that the raw data is converted into a Date before it is placed into a Record.
145 * The date format is specified in the constructor of the {@link Ext.data.Field} to which this type is
149 convert: function(v) {
150 var df = this.dateFormat;
158 if (df == 'timestamp') {
159 return new Date(v*1000);
162 return new Date(parseInt(v, 10));
164 return Ext.Date.parse(v, df);
167 var parsed = Date.parse(v);
168 return parsed ? new Date(parsed) : null;
175 Ext.apply(Ext.data.Types, {
176 <span id='Ext-data.Types-property-BOOLEAN'> /**
177 </span> * @type Object.
179 * <p>This data type means that the raw data is converted into a boolean before it is placed into
180 * a Record. The string "true" and the number 1 are converted to boolean <code>true</code>.</p>
181 * <p>The synonym <code>BOOL</code> is equivalent.</p>
185 <span id='Ext-data.Types-property-INTEGER'> /**
186 </span> * @type Object.
188 * This data type means that the raw data is converted into an integer before it is placed into a Record.
189 * <p>The synonym <code>INT</code> is equivalent.</p>
193 <span id='Ext-data.Types-property-NUMBER'> /**
194 </span> * @type Object.
196 * This data type means that the raw data is converted into a number before it is placed into a Record.
197 * <p>The synonym <code>FLOAT</code> is equivalent.</p>
202 </pre></pre></body></html>