PDA

View Full Version : [CLOSED] Adding a Convert handler to a ModelField created dynamically



tnwheeler
Sep 26, 2014, 12:36 AM
I am generating a datastore in my C# codebehind that looks kind of like this:


<ext:Store ID="stor1" runat="server" DataSourceID="sds1">
<Model>
<ext:Model runat="server" ID = "modlData" IDProperty = "StudentSeatLabel" >
<Fields>
<ext:ModelField Name="StudentSeatLabel" />
<ext:ModelField Name="StudentSeatLabelLength" Type="Int" />
<ext:ModelField Name="StudentSeatLabelSort" Type="String" >
<Convert Handler="return getSortableSeatNumber(record)" />
</ext:ModelField>
</Fields>
</ext:Model>
</ext:Store>



The first two fields are easy:


this.stor1.Model.Clear();
this.stor1.Model.Add(new Model { ID = "modlData", IDProperty = "StudentSeatLabel" });
this.stor1.Model[0].Fields.Add(new ModelField("StudentSeatLabel"));
this.stor1.Model[0].Fields.Add(new ModelField.Config { Name = "StudentSeatLabelLength", Type = ModelFieldType.Int });
this.stor1.Model[0].Fields.Add(new ModelField.Config { Name = "StudentSeatLabelSort", Type = ModelFieldType.Int });


However when I try to set the Convert property I am told it is read only. How can I configure this dynamic store to match the markup previously listed. (I am using Ext.net 2.5)

Thanks in advance.

Daniil
Sep 26, 2014, 12:38 PM
Hi @tnwheeler,

It is how you can initialize read-only properties.
Example

new ModelField
{
Name = "Name",
Convert =
{
Handler = "return 'something';"
}
}

tnwheeler
Sep 26, 2014, 8:37 PM
Thanks @Daniil !


That worked like a charm.