2 * Ext JS Library 2.2.1
\r
3 * Copyright(c) 2006-2009, Ext JS, LLC.
\r
4 * licensing@extjs.com
\r
6 * http://extjs.com/license
\r
10 * @class Ext.data.Field
\r
11 * <p>This class encpasulates the field definition information specified in the field definition objects
\r
12 * passed to {@link Ext.data.Record#create}.</p>
\r
13 * <p>Developers do not need to instantiate this class. Instances are created by {@link Ext.data.Record.create}
\r
14 * and cached in the {@link Ext.data.Record#fields fields} property of the created Record constructor's <b>prototype.</b></p>
\r
16 Ext.data.Field = function(config){
\r
17 if(typeof config == "string"){
\r
18 config = {name: config};
\r
20 Ext.apply(this, config);
\r
26 var st = Ext.data.SortTypes;
\r
27 // named sortTypes are supported, here we look them up
\r
28 if(typeof this.sortType == "string"){
\r
29 this.sortType = st[this.sortType];
\r
32 // set default sortType for strings and dates
\r
36 this.sortType = st.asUCString;
\r
39 this.sortType = st.asDate;
\r
42 this.sortType = st.none;
\r
47 var stripRe = /[\$,%]/g;
\r
49 // prebuilt conversion function for this field, instead of
\r
50 // switching every time we're reading a value
\r
52 var cv, dateFormat = this.dateFormat;
\r
57 cv = function(v){ return v; };
\r
60 cv = function(v){ return (v === undefined || v === null) ? '' : String(v); };
\r
64 return v !== undefined && v !== null && v !== '' ?
\r
65 parseInt(String(v).replace(stripRe, ""), 10) : '';
\r
70 return v !== undefined && v !== null && v !== '' ?
\r
71 parseFloat(String(v).replace(stripRe, ""), 10) : '';
\r
76 cv = function(v){ return v === true || v === "true" || v == 1; };
\r
87 if(dateFormat == "timestamp"){
\r
88 return new Date(v*1000);
\r
90 if(dateFormat == "time"){
\r
91 return new Date(parseInt(v, 10));
\r
93 return Date.parseDate(v, dateFormat);
\r
95 var parsed = Date.parse(v);
\r
96 return parsed ? new Date(parsed) : null;
\r
105 Ext.data.Field.prototype = {
\r
107 * @cfg {String} name
\r
108 * The name by which the field is referenced within the Record. This is referenced by,
\r
109 * for example, the <em>dataIndex</em> property in column definition objects passed to {@link Ext.grid.ColumnModel}
\r
112 * @cfg {String} type
\r
113 * (Optional) The data type for conversion to displayable value. Possible values are
\r
114 * <ul><li>auto (Default, implies no conversion)</li>
\r
119 * <li>date</li></ul>
\r
122 * @cfg {Function} convert
\r
123 * (Optional) A function which converts the value provided by the Reader into an object that will be stored
\r
124 * in the Record. It is passed the following parameters:<ul>
\r
125 * <li><b>v</b> : Mixed<div class="sub-desc">The data value as read by the Reader.</div></li>
\r
126 * <li><b>rec</b> : Mixed<div class="sub-desc">The data object containing the row as read by the Reader.
\r
127 * Depending on Reader type, this could be an Array, an object, or an XML element.</div></li>
\r
131 * @cfg {String} dateFormat
\r
132 * (Optional) A format string for the {@link Date#parseDate Date.parseDate} function, or "timestamp" if the
\r
133 * value provided by the Reader is a UNIX timestamp, or "time" if the value provided by the Reader is a
\r
134 * javascript millisecond timestamp.
\r
138 * @cfg {Mixed} defaultValue
\r
139 * (Optional) The default value used <b>when a Record is being created by a
\r
140 * {@link Ext.data.Reader Reader}</b> when the item referenced by the <b><tt>mapping</tt></b> does not exist in the data object
\r
141 * (i.e. undefined). (defaults to "")
\r
145 * @cfg {String} mapping
\r
146 * (Optional) A path specification for use by the {@link Ext.data.Reader} implementation
\r
147 * that is creating the Record to access the data value from the data object. If an {@link Ext.data.JsonReader}
\r
148 * is being used, then this is a string containing the javascript expression to reference the data relative to
\r
149 * the Record item's root. If an {@link Ext.data.XmlReader} is being used, this is an {@link Ext.DomQuery} path
\r
150 * to the data item relative to the Record element. If the mapping expression is the same as the field name,
\r
151 * this may be omitted.
\r
155 * @cfg {Function} sortType
\r
156 * (Optional) A function which converts a Field's value to a comparable value in order to ensure correct
\r
157 * sort ordering. Predefined functions are provided in {@link Ext.data.SortTypes}
\r
161 * @cfg {String} sortDir
\r
162 * (Optional) Initial direction to sort. "ASC" or "DESC"
\r