|
override string | InstanceOf [get] |
|
virtual bool | AllowNull [get, set] |
| Use when converting received data into a int, float, bool or string type. If the value cannot be parsed, null will be used if allowNull is true, otherwise a default value for that type will be used: for int and float - 0. for string - "". for bool - false. Note that when parsing of date type fails, the value will be null regardless of this setting. More...
|
|
virtual JFunction | Calculate [get] |
| This config defines a simple field calculation function. A calculate method only has access to the record data and should return the value of the calculated field. When provided in this way, the depends config is automatically determined by parsing the calculate function. More...
|
|
virtual ? bool? | Critical [get, set] |
| A critical field is a field that must always be sent to the server even if it has not changed. The most common example of such a field is the "id" of a record (see Ext.data.Model.idProperty but the Ext.data.Model.versionProperty is similarly a critical field. Defaults to: false More...
|
|
virtual string | Name [get, set] |
| The name by which the field is referenced within the Model. This is referenced by, for example, the dataIndex property in column definition objects passed to Ext.grid.header.Container. More...
|
|
virtual string? | NameProxy [get] |
|
virtual string | Mapping [get, set] |
| (Optional) A path expression for use by the Ext.data.reader.Reader implementation that is creating the Model to extract the Field value from the data object. If the path expression is the same as the field name, the mapping may be omitted. More...
|
|
virtual JFunction | MappingFunction [get] |
| Configure a mapping function to do complex data extraction. More...
|
|
virtual string | ServerMapping [get, set] |
|
virtual ModelFieldType | Type [get, set] |
| (Optional) The data type for automatic conversion from received data to the stored value if convert has not been specified. This may be specified as a string value. Possible values are More...
|
|
virtual string | TypeProxy [get] |
|
virtual SortTypeMethod | SortType [get, set] |
| A function which converts a Field's value to a comparable value in order to ensure correct sort ordering. Predefined functions are provided in Ext.data.SortTypes. More...
|
|
virtual SortDirection | SortDir [get, set] |
| Initial direction to sort ("ASC" or "DESC"). Defaults to "ASC". More...
|
|
virtual EmptyValue | SubmitEmptyValue [get, set] |
| Empty value representation during saving (default value as None) More...
|
|
virtual JFunction | CustomSortType [get] |
| A function which converts a Field's value to a comparable value in order to ensure correct sort ordering. A custom sort example: More...
|
|
virtual JFunction | Serialize [get] |
| A function which converts the Model's value for this Field into a form which can be used by whatever Writer is being used to sync data with the server. More...
|
|
virtual JFunction | Convert [get] |
| (Optional) A function which converts the value provided by the Reader into an object that will be stored in the Model. It is passed the following parameters: More...
|
|
virtual bool | NullConvert [get, set] |
| If you ensure that data comes with correct format then convert can be set to null, it increase a parsing performance More...
|
|
virtual string? | NullConvertProxy [get] |
|
virtual string?? | DateFormat [get, set] |
| (Optional) Used when converting received data into a Date when the type is specified as "date". More...
|
|
virtual string | DateWriteFormat [get, set] |
| Used to provide a custom format when serializing dates with a writer. If this is not specified, the DateFormat will be used. More...
|
|
virtual string | DateReadFormat [get, set] |
| Used when converting received data into a Date when the Type is specified as "Date". This configuration takes precedence over DateFormat. More...
|
|
virtual string | DefaultValue [get, set] |
| (Optional) The default value used when a Model is being created by a Reader when the item referenced by the mapping does not exist in the data object (i.e. undefined). (defaults to "") More...
|
|
virtual ? bool? | Persist [get, set] |
| False to exclude this field from the Ext.data.Model.modified fields in a model. This will also exclude the field from being written using a Ext.data.writer.Writer. This option is useful when model fields are used to keep state on the client but do not need to be persisted to the server. Defaults to true. More...
|
|
virtual bool | HtmlEncode [get, set] |
| Configure true to encode html in the field before sync More...
|
|
virtual string | ModelName [get, set] |
| The Ext.data.Model associated with this field More...
|
|
virtual ModelCollection | Model [get] |
|
virtual Model | ModelInstance [get] |
|
virtual ModelFieldCollection | Fields [get] |
| The fields for this complex field. More...
|
|
virtual string[] | Depends [get, set] |
| The field name or names within the Model on which the value of this field depends, and from which a new value may be calculated. These values are the values used by the convert method. If you do not have a convert method then this config should not be specified. Before using this config you should consider if using a calculate method instead of a convert method would be simpler. Whenever any of the named fields are set using the set method, this fields will have its convert method called passing the record so that the dependent value can be calculated from all fields which it needs. More...
|
|
virtual bool | Unique [get, set] |
| true if the value of this field is unique amongst all instances. When used with a reference this describes a "one-to-one" relationship. It is almost always the case that a unique field cannot also be nullable. More...
|
|
virtual string | ReferenceString [get, set] |
| The name of the entity referenced by this field. In most databases, this relationship is represented by a "foreign key". That is, a value for such a field matches the value of the id for an entity of this type. More...
|
|
virtual FieldReference | Reference [get, set] |
| Reference can also describe ownership between the entities More...
|
|
virtual string | VersionProperty [get, set] |
| If specified, this is the name of the property that contains the entity "version". The version property is used to manage a long-running transaction and allows the detection of simultaneous modification. The way a version property is used is that the client receives the version as it would any other entity property. When saving an entity, this property is always included in the request and the server uses the value in a "conditional update". If the current version of the entity on the server matches the version property sent by the client, the update is allowed. Otherwise, the update fails. On successful update, both the client and server increment the version. This is done on the server in the conditional update and on the client when it receives a success on its update request. More...
|
|
string | PropertyName [get] |
|
override ConfigOptionsCollection | ConfigOptions [get] |
|
virtual string | InstanceOf [get] |
|
ItemState | State [get] |
|
virtual DefaultValueMode | DefaultValueMode [get, set] |
|
virtual bool | DesignMode [get] |
|
bool | AutoDataBind [get, set] |
|
ResourceManager | ResourceManager [get] |
|
virtual Control | Owner [get, set] |
| The Owner Control for this Listener. More...
|
|
virtual bool | IsDefault [get] |
| Does this object currently represent it's default state. More...
|
|
bool | IsTrackingViewState [get] |
|
EventHandlerList | Events [get] |
|
EventHandler | DataBinding |
|
Control?? | BindingContainer [get] |
|
virtual ConfigItemCollection?? | CustomConfig [get] |
| Collection of custom js config More...
|
|
virtual ConfigOptionsCollection | ConfigOptions [get] |
|
virtual ConfigOptionsExtraction | ConfigOptionsExtraction [get] |
|
System.Web.Mvc.HtmlHelper?? | HtmlHelper [get, set] |
|
ConfigOptionsCollection | ConfigOptions [get] |
|
ConfigOptionsExtraction | ConfigOptionsExtraction [get] |
|
DefaultValueMode | DefaultValueMode [get, set] |
|
string | PropertyName [get] |
|
Fields are used to define what a Model is. They aren't instantiated directly - instead, when we create a class that extends Ext.data.Model, it will automatically create a Field instance for each field configured in a Model. For example, we might set up a model like this:
Ext.define('User', { extend: 'Ext.data.Model', fields: [ 'name', 'email', {name: 'age', type: 'int'}, {name: 'gender', type: 'string', defaultValue: 'Unknown'} ] }); Four fields will have been created for the User Model - name, email, age and gender. Note that we specified a couple of different formats here; if we only pass in the string name of the field (as with name and email), the field is set up with the 'auto' type. It's as if we'd done this instead:
Ext.define('User', { extend: 'Ext.data.Model', fields: [ {name: 'name', type: 'auto'}, {name: 'email', type: 'auto'}, {name: 'age', type: 'int'}, {name: 'gender', type: 'string', defaultValue: 'Unknown'} ] }); Types and conversion
The type is important - it's used to automatically convert data passed to the field into the correct format. In our example above, the name and email fields used the 'auto' type and will just accept anything that is passed into them. The 'age' field had an 'int' type however, so if we passed 25.4 this would be rounded to 25.
Sometimes a simple type isn't enough, or we want to perform some processing when we load a Field's data. We can do this using a convert function. Here, we're going to create a new field based on another:
Ext.define('User', { extend: 'Ext.data.Model', fields: [ 'name', 'email', {name: 'age', type: 'int'}, {name: 'gender', type: 'string', defaultValue: 'Unknown'},
{ name: 'firstName', convert: function(value, record) { var fullName = record.get('name'), splits = fullName.split(" "), firstName = splits[0];
return firstName; } } ] }); Now when we create a new User, the firstName is populated automatically based on the name:
var ed = Ext.create('User', {name: 'Ed Spencer'});
console.log(ed.get('firstName')); //logs 'Ed', based on our convert function In fact, if we log out all of the data inside ed, we'll see this:
console.log(ed.data);
//outputs this: { age: 0, email: "", firstName: "Ed", gender: "Unknown", name: "Ed Spencer" } The age field has been given a default of zero because we made it an int type. As an auto field, email has defaulted to an empty string. When we registered the User model we set gender's defaultValue to 'Unknown' so we see that now. Let's correct that and satisfy ourselves that the types work as we expect:
ed.set('gender', 'Male'); ed.get('gender'); //returns 'Male'
ed.set('age', 25.4); ed.get('age'); //returns 25 - we wanted an int, not a float, so no decimal places allowed
(Optional) A function which converts the value provided by the Reader into an object that will be stored in the Model. It is passed the following parameters:
value : Mixed The data value as read by the Reader, if undefined will use the configured defaultValue. record : Ext.data.Model The data object containing the Model as read so far by the Reader. Note that the Model may not be fully populated at this point as the fields are read in the order that they are defined in your fields array.
// example of convert function function fullName(v, record){ return record.name.last + ', ' + record.name.first; }
function location(v, record){ return !record.city ? '' : (record.city + ', ' + record.state); }
var Dude = Ext.regModel({ fields: [ {name: 'fullname', convert: fullName}, {name: 'firstname', mapping: 'name.first'}, {name: 'lastname', mapping: 'name.last'}, {name: 'city', defaultValue: 'homeless'}, 'state', {name: 'location', convert: location} ] });
// create the data store var store = new Ext.data.Store({ reader: { type: 'json', model: 'Dude', idProperty: 'key', root: 'daRoot', totalProperty: 'total' } });
var myData = [ { key: 1, name: { first: 'Fat', last: 'Albert' } // notice no city, state provided in data object }, { key: 2, name: { first: 'Barney', last: 'Rubble' }, city: 'Bedrock', state: 'Stoneridge' }, { key: 3, name: { first: 'Cliff', last: 'Claven' }, city: 'Boston', state: 'MA' } ];