What is the best way to create a calculated field in a Dextop C# model that does the following:
Creates the value for the FullName field based both the FirstName and LastName fields, similar to the following in ExtJs:
function fullName(v, record){
return record.name.last + ', ' + record.name.first;
}
Ext.define('Contact', {
extend: 'Ext.data.Model',
fields: [
{name: 'fullname', convert: fullName},
{name: 'firstname', mapping: 'name.first'},
{name: 'lastname', mapping: 'name.last'}
]
});
Updates the FullName field in realtime as the user is typing in either the FirstName or LastName fields on the form.
C# model code:
[DextopModel]
[DextopGrid]
[DextopForm]
class MyModel
{
[DextopModelId]
[DextopGridColumn(width = 50, readOnly=true)]
public int Id { get; set; }
[DextopFormField(anchor = "0", allowBlank = false, labelAlign = "top")]
[DextopGridColumn()]
public String FirstName { get; set; }
[DextopFormField(anchor = "0", allowBlank = false, labelAlign = "top")]
[DextopGridColumn()]
public String LastName { get; set; }
[DextopFormField(anchor="0", readOnly=true, labelAlign = "top")]
[DextopGridColumn(flex=1)]
public String FullName { get; set; }
}
Answer is very simple. Dextop supports calculated columns on the server side. Change the FullName property like in the sample below.
As an alternative you can use DextopModelField attribute to specify convert function which will be generated in the model.