3 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
4 <title>The source code</title>
5 <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
6 <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
8 <body onload="prettyPrint();">
9 <pre class="prettyprint lang-js">/*!
10 * Ext JS Library 3.3.1
11 * Copyright(c) 2006-2010 Sencha Inc.
12 * licensing@sencha.com
13 * http://www.sencha.com/license
15 <div id="cls-Ext.data.Field"></div>/**
16 * @class Ext.data.Field
17 * <p>This class encapsulates the field definition information specified in the field definition objects
18 * passed to {@link Ext.data.Record#create}.</p>
19 * <p>Developers do not need to instantiate this class. Instances are created by {@link Ext.data.Record.create}
20 * and cached in the {@link Ext.data.Record#fields fields} property of the created Record constructor's <b>prototype.</b></p>
22 Ext.data.Field = Ext.extend(Object, {
24 constructor : function(config){
25 if(Ext.isString(config)){
26 config = {name: config};
28 Ext.apply(this, config);
30 var types = Ext.data.Types,
35 if(Ext.isString(this.type)){
36 this.type = Ext.data.Types[this.type.toUpperCase()] || types.AUTO;
39 this.type = types.AUTO;
42 // named sortTypes are supported, here we look them up
44 this.sortType = Ext.data.SortTypes[st];
45 }else if(Ext.isEmpty(st)){
46 this.sortType = this.type.sortType;
50 this.convert = this.type.convert;
54 <div id="cfg-Ext.data.Field-name"></div>/**
56 * The name by which the field is referenced within the Record. This is referenced by, for example,
57 * the <code>dataIndex</code> property in column definition objects passed to {@link Ext.grid.ColumnModel}.
58 * <p>Note: In the simplest case, if no properties other than <code>name</code> are required, a field
59 * definition may consist of just a String for the field name.</p>
61 <div id="cfg-Ext.data.Field-type"></div>/**
63 * (Optional) The data type for automatic conversion from received data to the <i>stored</i> value if <code>{@link Ext.data.Field#convert convert}</code>
64 * has not been specified. This may be specified as a string value. Possible values are
65 * <div class="mdetail-params"><ul>
66 * <li>auto (Default, implies no conversion)</li>
71 * <li>date</li></ul></div>
72 * <p>This may also be specified by referencing a member of the {@link Ext.data.Types} class.</p>
73 * <p>Developers may create their own application-specific data types by defining new members of the
74 * {@link Ext.data.Types} class.</p>
76 <div id="cfg-Ext.data.Field-convert"></div>/**
77 * @cfg {Function} convert
78 * (Optional) A function which converts the value provided by the Reader into an object that will be stored
79 * in the Record. It is passed the following parameters:<div class="mdetail-params"><ul>
80 * <li><b>v</b> : Mixed<div class="sub-desc">The data value as read by the Reader, if undefined will use
81 * the configured <code>{@link Ext.data.Field#defaultValue defaultValue}</code>.</div></li>
82 * <li><b>rec</b> : Mixed<div class="sub-desc">The data object containing the row as read by the Reader.
83 * Depending on the Reader type, this could be an Array ({@link Ext.data.ArrayReader ArrayReader}), an object
84 * ({@link Ext.data.JsonReader JsonReader}), or an XML element ({@link Ext.data.XMLReader XMLReader}).</div></li>
87 // example of convert function
88 function fullName(v, record){
89 return record.name.last + ', ' + record.name.first;
92 function location(v, record){
93 return !record.city ? '' : (record.city + ', ' + record.state);
96 var Dude = Ext.data.Record.create([
97 {name: 'fullname', convert: fullName},
98 {name: 'firstname', mapping: 'name.first'},
99 {name: 'lastname', mapping: 'name.last'},
100 {name: 'city', defaultValue: 'homeless'},
102 {name: 'location', convert: location}
105 // create the data store
106 var store = new Ext.data.Store({
107 reader: new Ext.data.JsonReader(
111 totalProperty: 'total'
119 name: { first: 'Fat', last: 'Albert' }
120 // notice no city, state provided in data object
123 name: { first: 'Barney', last: 'Rubble' },
124 city: 'Bedrock', state: 'Stoneridge'
127 name: { first: 'Cliff', last: 'Claven' },
128 city: 'Boston', state: 'MA'
133 <div id="cfg-Ext.data.Field-dateFormat"></div>/**
134 * @cfg {String} dateFormat
135 * <p>(Optional) Used when converting received data into a Date when the {@link #type} is specified as <code>"date"</code>.</p>
136 * <p>A format string for the {@link Date#parseDate Date.parseDate} function, or "timestamp" if the
137 * value provided by the Reader is a UNIX timestamp, or "time" if the value provided by the Reader is a
138 * javascript millisecond timestamp. See {@link Date}</p>
142 <div id="cfg-Ext.data.Field-useNull"></div>/**
143 * @cfg {Boolean} useNull
144 * <p>(Optional) Use when converting received data into a Number type (either int or float). If the value cannot be parsed,
145 * null will be used if useNull is true, otherwise the value will be 0. Defaults to <tt>false</tt>
149 <div id="cfg-Ext.data.Field-defaultValue"></div>/**
150 * @cfg {Mixed} defaultValue
151 * (Optional) The default value used <b>when a Record is being created by a {@link Ext.data.Reader Reader}</b>
152 * when the item referenced by the <code>{@link Ext.data.Field#mapping mapping}</code> does not exist in the data
153 * object (i.e. undefined). (defaults to "")
156 <div id="cfg-Ext.data.Field-mapping"></div>/**
157 * @cfg {String/Number} mapping
158 * <p>(Optional) A path expression for use by the {@link Ext.data.DataReader} implementation
159 * that is creating the {@link Ext.data.Record Record} to extract the Field value from the data object.
160 * If the path expression is the same as the field name, the mapping may be omitted.</p>
161 * <p>The form of the mapping expression depends on the Reader being used.</p>
162 * <div class="mdetail-params"><ul>
163 * <li>{@link Ext.data.JsonReader}<div class="sub-desc">The mapping is a string containing the javascript
164 * expression to reference the data from an element of the data item's {@link Ext.data.JsonReader#root root} Array. Defaults to the field name.</div></li>
165 * <li>{@link Ext.data.XmlReader}<div class="sub-desc">The mapping is an {@link Ext.DomQuery} path to the data
166 * item relative to the DOM element that represents the {@link Ext.data.XmlReader#record record}. Defaults to the field name.</div></li>
167 * <li>{@link Ext.data.ArrayReader}<div class="sub-desc">The mapping is a number indicating the Array index
168 * of the field's value. Defaults to the field specification's Array position.</div></li>
170 * <p>If a more complex value extraction strategy is required, then configure the Field with a {@link #convert}
171 * function. This is passed the whole row object, and may interrogate it in whatever way is necessary in order to
172 * return the desired data.</p>
175 <div id="cfg-Ext.data.Field-sortType"></div>/**
176 * @cfg {Function} sortType
177 * (Optional) A function which converts a Field's value to a comparable value in order to ensure
178 * correct sort ordering. Predefined functions are provided in {@link Ext.data.SortTypes}. A custom
179 * sort example:<pre><code>
180 // current sort after sort we want
181 // +-+------+ +-+------+
182 // |1|First | |1|First |
183 // |2|Last | |3|Second|
184 // |3|Second| |2|Last |
185 // +-+------+ +-+------+
187 sortType: function(value) {
188 switch (value.toLowerCase()) // native toLowerCase():
190 case 'first': return 1;
191 case 'second': return 2;
198 <div id="cfg-Ext.data.Field-sortDir"></div>/**
199 * @cfg {String} sortDir
200 * (Optional) Initial direction to sort (<code>"ASC"</code> or <code>"DESC"</code>). Defaults to
201 * <code>"ASC"</code>.
204 <div id="cfg-Ext.data.Field-allowBlank"></div>/**
205 * @cfg {Boolean} allowBlank
206 * (Optional) Used for validating a {@link Ext.data.Record record}, defaults to <code>true</code>.
207 * An empty value here will cause {@link Ext.data.Record}.{@link Ext.data.Record#isValid isValid}
208 * to evaluate to <code>false</code>.