PDA

View Full Version : [CLOSED] Convert JsonReader.Fields from Ext.NET v1.3 to V2.x



UnifyEducation
May 02, 2012, 5:33 PM
Hi,

Could you tell me how to convert JsonReader.Fields to Ext.NET V2.x. Because


14.1 RecordField has been renamed to ModelField and must be defined in Model.

Reader .Fields has been removed.

Here is my code:


public GridPanel GetGridFromQE(string tableName)
{
var dbHelpers = new DataHelpers();

DataSet ds = dbHelpers.GetDataFromQueryEngine(tableName);
var dt = ds.Tables[0];

var reader = new JsonReader();

var store = new Store
{
ID = "Store1",
Reader = { reader }
};

var grid = new GridPanel
{
ID = tableName,
Height = 400,
Store = { store },
Title = tableName,
Frame = true
};



foreach (DataColumn column in dt.Columns)
{
//The problem is here: reader.Fields doesn't exist
reader.Fields.Add(column.ColumnName, MappingType(column.DataType));
grid.ColumnModel.Columns.Add(new Column { Text = column.ColumnName, DataIndex = column.ColumnName, Width = 200 });
}

store.DataSource = dt;
store.DataBind();

return grid;
}
private ModelFieldType MappingType(Type type)
{
if (type == typeof(string))
{
return ModelFieldType.String;
}
if (type == typeof(DateTime))
{
return ModelFieldType.Date;
}
if (type == typeof(int))
{
return ModelFieldType.Int;
}
if (type == typeof(double))
{
return ModelFieldType.Float;
}
if (type == typeof(bool))
{
return ModelFieldType.Boolean;
}

return ModelFieldType.Auto;
}

In version 2, Reader.Fields has been removed, so I don't know how to reuse this code in Ext.NET v2
Great thanks for your help

Daniil
May 02, 2012, 9:33 PM
Hi,

You should add ModelFields into Model.Fields, then that Model into Store.Model.

Example

Store store = new Store();

store.Reader.Add(new JsonReader());

Model model = new Model();
model.Fields.Add(new ModelField("field1"));
model.Fields.Add(new ModelField("field2"));
store.Model.Add(model);

UnifyEducation
May 03, 2012, 12:41 PM
It works now. Thanks for your help.

srikanthn27
Mar 12, 2015, 9:27 AM
My apologies for reopening an old thread. I'm having the same problem. In my aspx file, I have the following code:


<ext:JsonReader IDProperty="Id">
<field>
<ext:RecordField Name="Field1" Type="Int" />
<ext:RecordField Name="Field2" Type="String" />


If I change the field to Modelfield it still does not work. Can you please hand hold me to resolve this issue. Since I'm new, your hand holding will go a long way.

Regards,
Srikanth

Daniil
Mar 12, 2015, 9:39 AM
Hi @srikanthn27,


it still does not work

Please clarify what is exactly happening.

srikanthn27
Mar 12, 2015, 10:36 AM
Hello Danill,

Thank you for the reply. What I meant was, I changed from ReaderFields to ModelField and I get an error message saying

"Type 'Ext.Net.JsonReader' does not have a public property named 'Model'."


Below is my updated code:

<Reader>
<ext:JsonReader IDProperty="Id">
<Model>
<ext:Model runat="server"
<Fields>
<ext:ModelField Name="field1" Type="Int" />
<ext:ModelField Name="field2" Type="String" />
</Fields>
</ext:Model>
</Model>
</ext:JsonReader>
</Reader>
Please pardon my code formatting as I typed them in a hurry :-)

Daniil
Mar 12, 2015, 12:22 PM
Please edit the post wrapping the code in [CODE] tags.
Forum Guidelines For Posting New Topics (http://forums.ext.net/showthread.php?3440)