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

Page 1 of 2 12 LastLast
  1. #1

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

    Hi,

    I just want to post a problem and a solution for maybe helping others who will run into the same problem.

    If you add records ot a store like this:

    grid.store.add(new Ext.data.Record({ id: entries[i].id, text: entries[i].text, tableUid: entries[i].tableUid, dataId: entries[i].dataId }));
    I got the following exception "record.fields is undefined" after I updated from SVN (I guess its a problem with changes on ExtJS, not Ext.NET) since several months.

    Changing the code to the following lines will fix the problem:

       var ObjectRecordType = Ext.data.Record.create(['id', 'text', 'tableUid', 'dataId' ]);
       var rec = new ObjectRecordType({ id: entry.id, text: entry.text, tableUid: entry.tableUid, dataId: entry.dataId })
       grid.store.add(rec);
    HTH,

    Martin
    Last edited by geoffrey.mcgill; May 26, 2011 at 10:49 PM. Reason: [CLOSED]
  2. #2
    Hi Martin,

    Quote Originally Posted by macap View Post
    Hi,

    I just want to post a problem and a solution for maybe helping others who will run into the same problem.

    If you add records ot a store like this:

    grid.store.add(new Ext.data.Record({ id: entries[i].id, text: entries[i].text, tableUid: entries[i].tableUid, dataId: entries[i].dataId }));
    I got the following exception "record.fields is undefined" after I updated from SVN
    Please provide more details.

    Here is my test case which works fine.

    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 runat="server">
        <title>Ext.Net Example</title>
    </head>
    <body>
        <form runat="server">
        <ext:ResourceManager runat="server" />
        <ext:GridPanel ID="GridPanel1" runat="server" AutoHeight="true">
            <Store>
                <ext:Store runat="server">
                    <Reader>
                        <ext:JsonReader>
                            <Fields>
                                <ext:RecordField Name="test1" />
                                <ext:RecordField Name="test2" />
                                <ext:RecordField Name="test3" />
                            </Fields>
                        </ext:JsonReader>
                    </Reader>
                </ext:Store>
            </Store>
            <ColumnModel 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 runat="server" Text="Add">
            <Listeners>
                <Click Handler="GridPanel1.getStore().add(new Ext.data.Record({ test1: 'new 1', test2: 'new 2', test3: 'new 3' }));" />
            </Listeners>
        </ext:Button>
        </form>
    </body>
    </html>
  3. #3
    Hi Daniil,

    your example works fine for me too. Its really strange. I spent an half hour now to make your example "not working". Without any results ;-)

    Until now I cannot say why mine was not working with add new Ext.data.Record.
    All I know is that its working fine while using Ext.data.Record.create.


    Regards,

    Martin
  4. #4
    What are the Store and Readers configuration where it causes the error?
  5. #5
    I just was abled to build an example. Here you go:

     <%@ 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>
                            <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: 'new 1', 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: 'new 1', test2: 'new 2', test3: 'new 3' });
                GridPanel1.getStore().add(rec);
                " />
            </Listeners>
        </ext:Button>
        </form>
    </body>
    </html>

    The problem is the Add-Listener of the store which writes to an hidden field:

     <Add  Handler="SelectedObjects.setValue(Ext.encode(GridPanel1.getRowsValues(false)));" />
  6. #6
    It looks like a bug in .getRowsValues() but I'm not sure.

    Here is the modified and minimized test case.

    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 runat="server">
        <title>Ext.Net Example</title>
    </head>
    <body>
        <form runat="server">
        <ext:ResourceManager runat="server" />
        <ext:GridPanel ID="GridPanel1" runat="server" AutoHeight="true">
            <Store>
                <ext:Store runat="server">
                    <Reader>
                        <ext:JsonReader>
                            <Fields>
                                <ext:RecordField Name="test1" />
                                <ext:RecordField Name="test2" />
                                <ext:RecordField Name="test3" />
                            </Fields>
                        </ext:JsonReader>
                    </Reader>
                </ext:Store>
            </Store>
            <ColumnModel 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 runat="server" Text="Click me">
            <Listeners>
                <Click Handler="GridPanel1.getStore().add(new Ext.data.Record({ test1: 'new 1', test2: 'new 2', test3: 'new 3' }));" />
            </Listeners>
        </ext:Button>
        <ext:Button runat="server" Text="Then click me">
            <Listeners>
                <Click Handler="alert(Ext.encode(GridPanel1.getRowsValues(false)));" />
            </Listeners>
        </ext:Button>
        </form>
    </body>
    </html>
  7. #7
    Yes seems to me too.

    Maybe the ExtJS team checked in some code which was prepared for ExtJS 4.
    I played a bit around with Sencha Touch which has a similar MVC-Model like ExtJS 4 and thats why I got the idea to use Ext.data.Record.create.
  8. #8
    A note from the Ext.data.Record API:

    When serializing a Record for submission to the server, be aware that it contains many private properties, and also a reference to its owning Store which in turn holds references to its Records. This means that a whole Record may not be encoded using Ext.util.JSON.encode. Instead, use the data and id properties.


    But I think this has nothing to do with the exception we get in our example.
  9. #9
    Thanks for the thoughts.

    Yes, we use data and id only in .getRowsValues().

    Needing further investigation.
  10. #10
    Hi,

    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' }));" />
Page 1 of 2 12 LastLast

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