[CLOSED] record.fields is undefined after store.add(new Ext.Record(...))

Page 2 of 2 FirstFirst 12
  1. #11
    I need a cup of coffee:) I knew that it's incorrect to create a record using its constructor.

    Here is the quote from ExtJS docs.
    This constructor should not be used to create Record objects. Instead, use create to generate a subclass of Ext.data.Record configured with information about its constituent fields.
    http://dev.sencha.com/deploy/ext-3.3...&member=Record
  2. #12
    Hi,

    thanks for the hint.

    Quote Originally Posted by Vladimir View Post
    You create a record incorrectly, please use the following code
    <Click Handler="GridPanel1.getStore().add(new GridPanel1.store.recordType({ test1: 'new 1', test2: 'new 2', test3: 'new 3' }));" />

    Ok. But also if we used it incorrectly it worked at least until Ext.NET Rev. 3189.


    I just run into the next problem. Here is the extended example:

     <%@ Page Language="C#" %>
     
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
     
    <script runat="server">
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!X.IsAjaxRequest)
            {
                Store store = this.GridPanel1.GetStore();
                store.DataSource = new object[] 
                { 
                    new 
                    { 
                        test1 = "test11", 
                        test2 = "test12", 
                        test3 = "test13" 
                    },
                    new 
                    { 
                        test1 = "test21", 
                        test2 = "test22", 
                        test3 = "test23" 
                    },
                    new 
                    { 
                        test1 = "test31", 
                        test2 = "test32", 
                        test3 = "test33" 
                    }
                };
                store.DataBind();
            }
        }
    </script>
     
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head id="Head2" runat="server">
        <title>Ext.Net Example</title>
        <ext:ResourcePlaceHolder runat="server" />
        <script language="javascript">
            var ObjectRecordType = Ext.data.Record.create(['test1', 'test2', 'test3']);
        </script>
    </head>
    <body>
        <form id="Form2" runat="server">
        <ext:ResourceManager ID="ResourceManager2" runat="server" />
        
    <ext:Hidden ID="SelectedObjects" runat="server" EnableViewState="true" />
        <ext:GridPanel ID="GridPanel1" runat="server" AutoHeight="true">
            <Store>
                <ext:Store ID="Store2" runat="server">
                    <Reader>
                        <ext:JsonReader IDProperty="test1">
                            <Fields>
                                <ext:RecordField Name="test1" />
                                <ext:RecordField Name="test2" />
                                <ext:RecordField Name="test3" />
                            </Fields>
                        </ext:JsonReader>
                    </Reader>
                      <Listeners>
                <Add  Handler="SelectedObjects.setValue(Ext.encode(GridPanel1.getRowsValues(false)));" />
            </Listeners>
                </ext:Store>
            </Store>
            <ColumnModel ID="ColumnModel1" runat="server">
                <Columns>
                    <ext:Column Header="Test1" DataIndex="test1" />
                    <ext:Column Header="Test2" DataIndex="test2" />
                    <ext:Column Header="Test3" DataIndex="test3" />
                </Columns>
            </ColumnModel>
        </ext:GridPanel>
        <ext:Button ID="Button1" runat="server" Text="Add with Ext.data.Record">
            <Listeners>
                <Click Handler="GridPanel1.getStore().add(new Ext.data.Record({ test1: 'new1', test2: 'new 2', test3: 'new 3' }));" />
            </Listeners>
        </ext:Button>
          <ext:Button ID="Button2" runat="server" Text="Add Ext.data.Record.create">
            <Listeners>
                <Click Handler=" var rec = new ObjectRecordType({ test1: 'new1', test2: 'new 2', test3: 'new 3' });           
                GridPanel1.getStore().add(rec);
                " />
            </Listeners>
        </ext:Button>
         <ext:Button ID="Button4" runat="server" Text="Add GridPanel1.store.recordType">
            <Listeners>
                <Click Handler="   
                GridPanel1.getStore().add(new GridPanel1.store.recordType({ test1: 'new1', test2: 'new 2', test3: 'new 3' }));
                " />
            </Listeners>
        </ext:Button>
        <ext:Button ID="Button3" runat="server" Text="Then click me">
            <Listeners>
                <Click Handler="alert(Ext.encode(GridPanel1.getRowsValues(false)));" />
            </Listeners>
        </ext:Button>
        </form>
    </body>
    </html>

    If you add new data while clicking on a button it adds:

    "new1", "new 2", new 3"


    When you click on "Then click me" to see the encoded rows values you can see that the newly added records are encoded incorrectly:

    {"test1":-1,"test2":"new 2","test3":"new 3"},{"test1":-2,"test2":"new 2","test3":"new 3"}

    but I would expect to see:

    {"test1": "new1" ,"test2":"new 2","test3":"new 3"},{"test1": "new1","test2":"new 2","test3":"new 3"}

    And the problem is only with the new added values. The values which where added in codebehind before are encoded right.


    I am also very sure that this worked before at least until Ext.NET Rev. 3189.



    Regards,

    Martin
  3. #13
    Hi,

    recordType has second argument (id value)
    So, if you have id field then pass id as second argument
    new GridPanel1.store.recordType({ test1: 'new 1', test2: 'new 2', test3: 'new 3' }, 'new 1')
  4. #14
    Thank you very much. Now the UserControl works fine.

    But all in all....
    You would make me very happy if you would collect problems (also caused because of ExtJS updates) and changes like this in the changelog.
    It would make upgrading from SVN much easier.

    I will also try to help you as much as I can if you need any help. Just sent me a note via mail or skype.


    Regards,

    Martin
  5. #15
    Yes, but it would be too-too difficult to make a changelog for ExtJS.

    We would need to hire about 3-7 or more people for monitoring:)

    But they don't change anything that is described in their docs.

    Returning to the initial problem.

    They wrote in the docs:
    This constructor should not be used to create Record objects. Instead, use create to generate a subclass of Ext.data.Record configured with information about its constituent fields.
    as I mentioned in the post #11, so, don't use a constructor to create a record, in a different way your code can be broken in the future updating.
  6. #16
    Ok thanks. You are right. The API also helps if its already working ;-)

    And I understand that it would be too much work.


    What about creating another sub-forum for problems after upgrading?
    So people who run into trouble after upgrading can search or post there?

    Only an idea. ;-)


    Regards,

    Martin
  7. #17
    Quote Originally Posted by macap View Post
    What about creating another sub-forum for problems after upgrading?
    So people who run into trouble after upgrading can search or post there?
    Mm, not sure it will work, but sounds interesting. I will pass on the request.
    Last edited by geoffrey.mcgill; May 26, 2011 at 10:48 PM.
Page 2 of 2 FirstFirst 12

Similar Threads

  1. Replies: 4
    Last Post: Aug 16, 2012, 1:08 PM
  2. Replies: 1
    Last Post: Dec 22, 2011, 6:17 AM
  3. Replies: 8
    Last Post: May 30, 2011, 5:55 PM
  4. [CLOSED] Store.remove(record) and Store.reload()
    By capecod in forum 1.x Legacy Premium Help
    Replies: 2
    Last Post: Nov 08, 2010, 10:03 AM
  5. [CLOSED] Adding a new Store Record - Not a Record object
    By Steve in forum 1.x Legacy Premium Help
    Replies: 5
    Last Post: May 15, 2009, 7:40 AM

Tags for this Thread

Posting Permissions