3 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
\r
4 <title>The source code</title>
\r
5 <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
\r
6 <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
\r
8 <body onload="prettyPrint();">
\r
9 <pre class="prettyprint lang-js"><div id="cls-Ext.data.Field"></div>/**
10 * @class Ext.data.Field
11 * <p>This class encapsulates the field definition information specified in the field definition objects
12 * passed to {@link Ext.data.Record#create}.</p>
13 * <p>Developers do not need to instantiate this class. Instances are created by {@link Ext.data.Record.create}
14 * and cached in the {@link Ext.data.Record#fields fields} property of the created Record constructor's <b>prototype.</b></p>
16 Ext.data.Field = function(config){
17 if(typeof config == "string"){
18 config = {name: config};
20 Ext.apply(this, config);
26 var st = Ext.data.SortTypes;
27 // named sortTypes are supported, here we look them up
28 if(typeof this.sortType == "string"){
29 this.sortType = st[this.sortType];
32 // set default sortType for strings and dates
36 this.sortType = st.asUCString;
39 this.sortType = st.asDate;
42 this.sortType = st.none;
47 var stripRe = /[\$,%]/g;
49 // prebuilt conversion function for this field, instead of
50 // switching every time we're reading a value
52 var cv, dateFormat = this.dateFormat;
57 cv = function(v){ return v; };
60 cv = function(v){ return (v === undefined || v === null) ? '' : String(v); };
64 return v !== undefined && v !== null && v !== '' ?
65 parseInt(String(v).replace(stripRe, ""), 10) : '';
70 return v !== undefined && v !== null && v !== '' ?
71 parseFloat(String(v).replace(stripRe, ""), 10) : '';
75 cv = function(v){ return v === true || v === "true" || v == 1; };
86 if(dateFormat == "timestamp"){
87 return new Date(v*1000);
89 if(dateFormat == "time"){
90 return new Date(parseInt(v, 10));
92 return Date.parseDate(v, dateFormat);
94 var parsed = Date.parse(v);
95 return parsed ? new Date(parsed) : null;
99 cv = function(v){ return v; };
107 Ext.data.Field.prototype = {
108 <div id="cfg-Ext.data.Field-name"></div>/**
110 * The name by which the field is referenced within the Record. This is referenced by, for example,
111 * the <tt>dataIndex</tt> property in column definition objects passed to {@link Ext.grid.ColumnModel}.
112 * <p>Note: In the simplest case, if no properties other than <tt>name</tt> are required, a field
113 * definition may consist of just a String for the field name.</p>
115 <div id="cfg-Ext.data.Field-type"></div>/**
117 * (Optional) The data type for conversion to displayable value if <tt>{@link Ext.data.Field#convert convert}</tt>
118 * has not been specified. Possible values are
119 * <div class="mdetail-params"><ul>
120 * <li>auto (Default, implies no conversion)</li>
125 * <li>date</li></ul></div>
127 <div id="cfg-Ext.data.Field-convert"></div>/**
128 * @cfg {Function} convert
129 * (Optional) A function which converts the value provided by the Reader into an object that will be stored
130 * in the Record. It is passed the following parameters:<div class="mdetail-params"><ul>
131 * <li><b>v</b> : Mixed<div class="sub-desc">The data value as read by the Reader, if undefined will use
132 * the configured <tt>{@link Ext.data.Field#defaultValue defaultValue}</tt>.</div></li>
133 * <li><b>rec</b> : Mixed<div class="sub-desc">The data object containing the row as read by the Reader.
134 * Depending on the Reader type, this could be an Array ({@link Ext.data.ArrayReader ArrayReader}), an object
135 * ({@link Ext.data.JsonReader JsonReader}), or an XML element ({@link Ext.data.XMLReader XMLReader}).</div></li>
138 // example of convert function
139 function fullName(v, record){
140 return record.name.last + ', ' + record.name.first;
143 function location(v, record){
144 return !record.city ? '' : (record.city + ', ' + record.state);
147 var Dude = Ext.data.Record.create([
148 {name: 'fullname', convert: fullName},
149 {name: 'firstname', mapping: 'name.first'},
150 {name: 'lastname', mapping: 'name.last'},
151 {name: 'city', defaultValue: 'homeless'},
153 {name: 'location', convert: location}
156 // create the data store
157 var store = new Ext.data.Store({
158 reader: new Ext.data.JsonReader(
162 totalProperty: 'total'
170 name: { first: 'Fat', last: 'Albert' }
171 // notice no city, state provided in data object
174 name: { first: 'Barney', last: 'Rubble' },
175 city: 'Bedrock', state: 'Stoneridge'
178 name: { first: 'Cliff', last: 'Claven' },
179 city: 'Boston', state: 'MA'
184 <div id="cfg-Ext.data.Field-dateFormat"></div>/**
185 * @cfg {String} dateFormat
186 * (Optional) A format string for the {@link Date#parseDate Date.parseDate} function, or "timestamp" if the
187 * value provided by the Reader is a UNIX timestamp, or "time" if the value provided by the Reader is a
188 * javascript millisecond timestamp.
191 <div id="cfg-Ext.data.Field-defaultValue"></div>/**
192 * @cfg {Mixed} defaultValue
193 * (Optional) The default value used <b>when a Record is being created by a {@link Ext.data.Reader Reader}</b>
194 * when the item referenced by the <tt>{@link Ext.data.Field#mapping mapping}</tt> does not exist in the data
195 * object (i.e. undefined). (defaults to "")
198 <div id="cfg-Ext.data.Field-mapping"></div>/**
199 * @cfg {String/Number} mapping
200 * <p>(Optional) A path expression for use by the {@link Ext.data.DataReader} implementation
201 * that is creating the {@link Ext.data.Record Record} to extract the Field value from the data object.
202 * If the path expression is the same as the field name, the mapping may be omitted.</p>
203 * <p>The form of the mapping expression depends on the Reader being used.</p>
204 * <div class="mdetail-params"><ul>
205 * <li>{@link Ext.data.JsonReader}<div class="sub-desc">The mapping is a string containing the javascript
206 * 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>
207 * <li>{@link Ext.data.XmlReader}<div class="sub-desc">The mapping is an {@link Ext.DomQuery} path to the data
208 * item relative to the DOM element that represents the {@link Ext.data.XmlReader#record record}. Defaults to the field name.</div></li>
209 * <li>{@link Ext.data.ArrayReader}<div class="sub-desc">The mapping is a number indicating the Array index
210 * of the field's value. Defaults to the field specification's Array position.</div></li>
212 * <p>If a more complex value extraction strategy is required, then configure the Field with a {@link #convert}
213 * function. This is passed the whole row object, and may interrogate it in whatever way is necessary in order to
214 * return the desired data.</p>
217 <div id="cfg-Ext.data.Field-sortType"></div>/**
218 * @cfg {Function} sortType
219 * (Optional) A function which converts a Field's value to a comparable value in order to ensure
220 * correct sort ordering. Predefined functions are provided in {@link Ext.data.SortTypes}. A custom
221 * sort example:<pre><code>
222 // current sort after sort we want
223 // +-+------+ +-+------+
224 // |1|First | |1|First |
225 // |2|Last | |3|Second|
226 // |3|Second| |2|Last |
227 // +-+------+ +-+------+
229 sortType: function(value) {
230 switch (value.toLowerCase()) // native toLowerCase():
232 case 'first': return 1;
233 case 'second': return 2;
240 <div id="cfg-Ext.data.Field-sortDir"></div>/**
241 * @cfg {String} sortDir
242 * (Optional) Initial direction to sort (<tt>"ASC"</tt> or <tt>"DESC"</tt>). Defaults to
246 <div id="cfg-Ext.data.Field-allowBlank"></div>/**
247 * @cfg {Boolean} allowBlank
248 * (Optional) Used for validating a {@link Ext.data.Record record}, defaults to <tt>true</tt>.
249 * An empty value here will cause {@link Ext.data.Record}.{@link Ext.data.Record#isValid isValid}
250 * to evaluate to <tt>false</tt>.