Ext.NET  5.3.0
.NET Component Framework for Enterprise Level Apps
Ext.Net.ModelField Class Reference

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: More...

Inheritance diagram for Ext.Net.ModelField:
Ext.Net.BaseItem Ext.Net.IAlias Ext.Net.IXObject Ext.Net.IBase

Classes

class  Builder
 
class  Builder
 
class  Config
 

Public Member Functions

 ModelField ()
 
 ModelField (string name)
 
 ModelField (string name, ModelFieldType type)
 
 ModelField (string name, ModelFieldType type, string dateFormat)
 
ModelField.Builder ToBuilder ()
 
override IControlBuilder ToNativeBuilder ()
 
 ModelField (Config config)
 
- Public Member Functions inherited from Ext.Net.BaseItem
virtual bool HasExplicitValue (string name)
 
void EnsureDataBind ()
 
virtual void Call (string name)
 
virtual void Call (string name, params object[] args)
 
virtual void AddScript (string script)
 
virtual void AddScript (string script, params object[] args)
 
virtual bool IsEmptyObject ()
 
Apply< T > (IApply config)
 
BaseItem Apply (object config)
 
virtual void LoadViewState (object state)
 
virtual object SaveViewState ()
 
virtual void TrackViewState ()
 
void SetDirty ()
 
virtual void DataBind ()
 

Static Public Member Functions

static implicit operator ModelField (ModelField.Config config)
 

Properties

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]
 
- Properties inherited from Ext.Net.BaseItem
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]
 
- Properties inherited from Ext.Net.IXObject
ConfigOptionsCollection ConfigOptions [get]
 
ConfigOptionsExtraction ConfigOptionsExtraction [get]
 
DefaultValueMode DefaultValueMode [get, set]
 
- Properties inherited from Ext.Net.IAlias
string PropertyName [get]
 

Additional Inherited Members

- Protected Member Functions inherited from Ext.Net.BaseItem
 BaseItem (Control owner)
 
 BaseItem ()
 
virtual void OwnerUpdate (Control owner)
 
virtual void OnDataBinding (EventArgs e)
 

Detailed Description

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

Constructor & Destructor Documentation

◆ ModelField() [1/5]

Ext.Net.ModelField.ModelField ( )
inline

◆ ModelField() [2/5]

Ext.Net.ModelField.ModelField ( string  name)
inline

◆ ModelField() [3/5]

Ext.Net.ModelField.ModelField ( string  name,
ModelFieldType  type 
)
inline

◆ ModelField() [4/5]

Ext.Net.ModelField.ModelField ( string  name,
ModelFieldType  type,
string  dateFormat 
)
inline

◆ ModelField() [5/5]

Ext.Net.ModelField.ModelField ( Config  config)
inline

Member Function Documentation

◆ operator ModelField()

static implicit Ext.Net.ModelField.operator ModelField ( ModelField.Config  config)
inlinestatic

◆ ToBuilder()

ModelField.Builder Ext.Net.ModelField.ToBuilder ( )
inline

◆ ToNativeBuilder()

override IControlBuilder Ext.Net.ModelField.ToNativeBuilder ( )
inlinevirtual

Reimplemented from Ext.Net.BaseItem.

Property Documentation

◆ AllowNull

virtual bool Ext.Net.ModelField.AllowNull
getset

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.

◆ Calculate

virtual JFunction Ext.Net.ModelField.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.

For example,

fields: [{ name: 'firstName', type: 'string' },{ name: 'lastName', type: 'string' },{ name: 'fullName', calculate: function (data) { return data.firstName + ' ' + data.lastName; } }]

The restrictions on form for a calculate method are that the accesses to field values must match the following regular expression (case insensitive): data.([a-z_][a-z0-9_]*)

The only advantage of a calculate method over a convert method is automatic determination of depends.

◆ ConfigOptions

override ConfigOptionsCollection Ext.Net.ModelField.ConfigOptions
get

◆ Convert

virtual JFunction Ext.Net.ModelField.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:

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' } ];

◆ Critical

virtual ? bool? Ext.Net.ModelField.Critical
getset

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

◆ CustomSortType

virtual JFunction Ext.Net.ModelField.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:

// current sort after sort we want // +-+---—+ +-+---—+ // |1|First | |1|First | // |2|Last | |3|Second| // |3|Second| |2|Last | // +-+---—+ +-+---—+

sortType: function(value) { switch (value.toLowerCase()) // native toLowerCase(): { case 'first': return 1; case 'second': return 2; default: return 3; } }

◆ DateFormat

virtual string?? Ext.Net.ModelField.DateFormat
getset

(Optional) Used when converting received data into a Date when the type is specified as "date".

A format string for the Ext.Date.parse function, or "timestamp" if the value provided by the Reader is a UNIX timestamp, or "time" if the value provided by the Reader is a javascript millisecond timestamp.

It is quite important to note that while this config is optional, it will default to using the base JavaScript Date object's parse function if not specified, rather than Ext.Date.parse. This can cause unexpected issues, especially when converting between timezones, or when converting dates that do not have a timezone specified. The behavior of the native Date.parse is implementation-specific, and depending on the value of the date string, it might return the UTC date or the local date. For this reason it is strongly recommended that you always specify an explicit date format when parsing dates.

◆ DateReadFormat

virtual string Ext.Net.ModelField.DateReadFormat
getset

Used when converting received data into a Date when the Type is specified as "Date". This configuration takes precedence over DateFormat.

◆ DateWriteFormat

virtual string Ext.Net.ModelField.DateWriteFormat
getset

Used to provide a custom format when serializing dates with a writer. If this is not specified, the DateFormat will be used.

◆ DefaultValue

virtual string Ext.Net.ModelField.DefaultValue
getset

(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 "")

Please pay attention that if you use string const then need wrap like this DefaultValue="'String const'"

◆ Depends

virtual string [] Ext.Net.ModelField.Depends
getset

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.

◆ Fields

virtual ModelFieldCollection Ext.Net.ModelField.Fields
get

The fields for this complex field.

◆ HtmlEncode

virtual bool Ext.Net.ModelField.HtmlEncode
getset

Configure true to encode html in the field before sync

◆ InstanceOf

override string Ext.Net.ModelField.InstanceOf
get

◆ Mapping

virtual string Ext.Net.ModelField.Mapping
getset

(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.

The form of the mapping expression depends on the Reader being used.

Ext.data.reader.Json The mapping is a string containing the javascript expression to reference the data from an element of the data item's root Array. Defaults to the field name. Ext.data.reader.Xml The mapping is an Ext.DomQuery path to the data item relative to the DOM element that represents the record. Defaults to the field name. Ext.data.reader.Array The mapping is a number indicating the Array index of the field's value. Defaults to the field specification's Array position. If a more complex value extraction strategy is required, then configure the Field with a convert function. This is passed the whole row object, and may interrogate it in whatever way is necessary in order to return the desired data.

◆ MappingFunction

virtual JFunction Ext.Net.ModelField.MappingFunction
get

Configure a mapping function to do complex data extraction.

◆ Model

virtual ModelCollection Ext.Net.ModelField.Model
get

◆ ModelInstance

virtual Model Ext.Net.ModelField.ModelInstance
get

◆ ModelName

virtual string Ext.Net.ModelField.ModelName
getset

The Ext.data.Model associated with this field

◆ Name

virtual string Ext.Net.ModelField.Name
getset

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.

Note: In the simplest case, if no properties other than name are required, a field definition may consist of just a String for the field name.

◆ NameProxy

virtual string? Ext.Net.ModelField.NameProxy
getprotected

◆ NullConvert

virtual bool Ext.Net.ModelField.NullConvert
getset

If you ensure that data comes with correct format then convert can be set to null, it increase a parsing performance

◆ NullConvertProxy

virtual string? Ext.Net.ModelField.NullConvertProxy
getprotected

◆ Persist

virtual ? bool? Ext.Net.ModelField.Persist
getset

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.

◆ PropertyName

string Ext.Net.ModelField.PropertyName
get

◆ Reference

virtual FieldReference Ext.Net.ModelField.Reference
getset

Reference can also describe ownership between the entities

◆ ReferenceString

virtual string Ext.Net.ModelField.ReferenceString
getset

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.

◆ Serialize

virtual JFunction Ext.Net.ModelField.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.

The function should return a string which represents the Field's value.

It is passed the following parameters: value : Mixed The Field's value - the value to be serialized. record : Ext.data.Model The record being serialized.

◆ ServerMapping

virtual string Ext.Net.ModelField.ServerMapping
getset

◆ SortDir

virtual SortDirection Ext.Net.ModelField.SortDir
getset

Initial direction to sort ("ASC" or "DESC"). Defaults to "ASC".

◆ SortType

virtual SortTypeMethod Ext.Net.ModelField.SortType
getset

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.

◆ SubmitEmptyValue

virtual EmptyValue Ext.Net.ModelField.SubmitEmptyValue
getset

Empty value representation during saving (default value as None)

◆ Type

virtual ModelFieldType Ext.Net.ModelField.Type
getset

(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

auto (Default, implies no conversion) string int float boolean date This may also be specified by referencing a member of the Ext.data.Types class.

Developers may create their own application-specific data types by defining new members of the Ext.data.Types class.

◆ TypeProxy

virtual string Ext.Net.ModelField.TypeProxy
getprotected

◆ Unique

virtual bool Ext.Net.ModelField.Unique
getset

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.

◆ VersionProperty

virtual string Ext.Net.ModelField.VersionProperty
getset

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.


The documentation for this class was generated from the following files: