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.2.0
11 * Copyright(c) 2006-2010 Ext JS, Inc.
13 * http://www.extjs.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>
141 <div id="cfg-Ext.data.Field-defaultValue"></div>/**
142 * @cfg {Mixed} defaultValue
143 * (Optional) The default value used <b>when a Record is being created by a {@link Ext.data.Reader Reader}</b>
144 * when the item referenced by the <code>{@link Ext.data.Field#mapping mapping}</code> does not exist in the data
145 * object (i.e. undefined). (defaults to "")
148 <div id="cfg-Ext.data.Field-mapping"></div>/**
149 * @cfg {String/Number} mapping
150 * <p>(Optional) A path expression for use by the {@link Ext.data.DataReader} implementation
151 * that is creating the {@link Ext.data.Record Record} to extract the Field value from the data object.
152 * If the path expression is the same as the field name, the mapping may be omitted.</p>
153 * <p>The form of the mapping expression depends on the Reader being used.</p>
154 * <div class="mdetail-params"><ul>
155 * <li>{@link Ext.data.JsonReader}<div class="sub-desc">The mapping is a string containing the javascript
156 * 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>
157 * <li>{@link Ext.data.XmlReader}<div class="sub-desc">The mapping is an {@link Ext.DomQuery} path to the data
158 * item relative to the DOM element that represents the {@link Ext.data.XmlReader#record record}. Defaults to the field name.</div></li>
159 * <li>{@link Ext.data.ArrayReader}<div class="sub-desc">The mapping is a number indicating the Array index
160 * of the field's value. Defaults to the field specification's Array position.</div></li>
162 * <p>If a more complex value extraction strategy is required, then configure the Field with a {@link #convert}
163 * function. This is passed the whole row object, and may interrogate it in whatever way is necessary in order to
164 * return the desired data.</p>
167 <div id="cfg-Ext.data.Field-sortType"></div>/**
168 * @cfg {Function} sortType
169 * (Optional) A function which converts a Field's value to a comparable value in order to ensure
170 * correct sort ordering. Predefined functions are provided in {@link Ext.data.SortTypes}. A custom
171 * sort example:<pre><code>
172 // current sort after sort we want
173 // +-+------+ +-+------+
174 // |1|First | |1|First |
175 // |2|Last | |3|Second|
176 // |3|Second| |2|Last |
177 // +-+------+ +-+------+
179 sortType: function(value) {
180 switch (value.toLowerCase()) // native toLowerCase():
182 case 'first': return 1;
183 case 'second': return 2;
190 <div id="cfg-Ext.data.Field-sortDir"></div>/**
191 * @cfg {String} sortDir
192 * (Optional) Initial direction to sort (<code>"ASC"</code> or <code>"DESC"</code>). Defaults to
193 * <code>"ASC"</code>.
196 <div id="cfg-Ext.data.Field-allowBlank"></div>/**
197 * @cfg {Boolean} allowBlank
198 * (Optional) Used for validating a {@link Ext.data.Record record}, defaults to <code>true</code>.
199 * An empty value here will cause {@link Ext.data.Record}.{@link Ext.data.Record#isValid isValid}
200 * to evaluate to <code>false</code>.