Binding Store to Nest DataClass

  1. #1

    Binding Store to Nest DataClass

    Hello! I am trying to bind a nested DataClass to a store and having trouble with it. Basically, I have a class whose attributes are another class. This seems to be a problem because the DataReader only recognizes simple types (int, floating, date, and text) and doesn't seem to know how to handle other class.

    Is it possible to setup the store to properly parse the dataclass?

    Here's a simplified code:

    Class definitions in DataClasses.cs:

    public class Teacher
    {
        public string FirstName;
        public string LastName;
        public string TeacherID;
    
        public override ToString()
        {
            return LastName + ', ' + FirstName;
        }
    }
    
    public class Course 
    {
        public string CourseName;
        public int Course ID;
        public Teacher CourseTeacher;
    }
    
    public void Load_Data (object sender, StoreRefreshDataEventArgs e)
    {
        Course newData = new Course("John", "Doe", "1111");
        storeCourse.DataSource = newData;
        storeCourse.DataBind();
    }
    So we have a class Course, which contains Teacher class. I want to be able to load/save the Course with Teacher class included as an object in the store, while having the form display the Teacher's name.


    Now the aspx code would look something like:
    <ext:store runat="server" ID="storeClass" AutoLoad="true" AutoDataBind="false" onRefreshData="Load_Data">
        <Proxy>
            <ext:DataSourceProxy/>
        </Proxy>
        <Reader>
            <ext:JsonReader runat="server" ReaderID="CourseID">    
                <Fields>
                    <ext:RecordFields Name="CourseName"/>
                    <ext:RecordFields Name="CourseID"/>
                    <ext:RecordFields Name="CourseTeacher"/>
                </Fields>
            </ext:JsonReader>
        </Reader>
    </ext:store>
    
    <ext:Panel runat="server" ID="MainPanel">
    <Body>
        <ext:FormLayOut runat="server" StoreID="storeCourse" ID="CourseForm" AutoLoad="True">
            <ext:Anchor><ext:TextField runat="server" FieldLabel="Course Name" DataIndex="CourseName" ID="TxtCourseName"/></ext:Anchor>
            <ext:Anchor><ext:TextField runat="server" FieldLabel="Course ID" DataIndex="CourseID" ID="TxtCourseID"/></ext:Anchor>
            <ext:Anchor><ext:TextField runat="server"
    FieldLabel="Teacher" DataIndex="CourseTeacher" ID="TxtCourseTeacher"/></ext:Anchor>
        </ext:FormLayOut>
    </Body>
    </ext:Panel>
    So.. is there a way to configure either form or store to view a string representation of the Teacher's name on the form display, while keeping the Teacher Class as an attribute of Course within store?

    Any help would be appreciated! Thanks!

  2. #2

    RE: Binding Store to Nest DataClass

    Found a good example that explains me how to do this with Convert and setting the Serialization to "Complex" in the store:
    https://examples1.ext.net/#/GridPane.../Data_Prepare/

    Now.. I am getting an error on Save because it doesn't know how to save
    the Teacher attribute. Would I have to configure a writer conversion
    function? I am also getting error on the converted function on save because the converted field doesn't really exist in the class definition.

    StoreMapping won't work for me because I want to save the complex object as its own class, not a string representation.

    Edit: Hmm.. I realize that this is what I really want:
    https://examples1.ext.net/#/GridPane...Field_Mapping/
    But Renderer only works for GridPanel Columns?!

Similar Threads

  1. Problem in store binding
    By softlabsgroup.support in forum 1.x Help
    Replies: 0
    Last Post: Jun 09, 2012, 7:15 AM
  2. Store Data is not binding
    By Rahul in forum 1.x Help
    Replies: 7
    Last Post: Jul 27, 2011, 10:31 AM
  3. Binding json to store
    By pintun in forum 1.x Help
    Replies: 2
    Last Post: Apr 22, 2010, 11:16 AM
  4. [CLOSED] Store is not binding
    By majestic in forum 1.x Legacy Premium Help
    Replies: 3
    Last Post: Apr 01, 2010, 12:47 PM
  5. Nest Related Files in Visual Studio
    By jchau in forum Open Discussions
    Replies: 3
    Last Post: Dec 20, 2008, 10:48 PM

Posting Permissions