[CLOSED] Convert JsonReader.Fields from Ext.NET v1.3 to V2.x

  1. #1

    [CLOSED] Convert JsonReader.Fields from Ext.NET v1.3 to V2.x

    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
    Last edited by Daniil; May 03, 2012 at 11:45 AM. Reason: [CLOSED]
  2. #2
    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);
  3. #3
    It works now. Thanks for your help.
  4. #4

    Where to Make the changes

    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
    Last edited by Daniil; Mar 12, 2015 at 8:37 AM. Reason: Please use [CODE] tags
  5. #5
    Hi @srikanthn27,

    it still does not work
    Please clarify what is exactly happening.
  6. #6
    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 :-)
  7. #7
    Please edit the post wrapping the code in [CODE] tags.
    Forum Guidelines For Posting New Topics

Similar Threads

  1. Replies: 0
    Last Post: Dec 01, 2011, 6:43 AM
  2. [CLOSED] Using JsonReader and everything is empty
    By Bert76 in forum 1.x Legacy Premium Help
    Replies: 13
    Last Post: Jul 18, 2011, 5:39 PM
  3. HttpProxy and JsonReader
    By santosbj in forum 1.x Help
    Replies: 1
    Last Post: Jun 18, 2010, 5:29 AM
  4. Replies: 9
    Last Post: Oct 28, 2009, 3:10 PM
  5. JsonReader - Htmlencode Specific Fields
    By jp500 in forum 1.x Help
    Replies: 0
    Last Post: Nov 12, 2008, 7:50 PM

Posting Permissions