[CLOSED] Store loadData() wierd error.

  1. #1

    [CLOSED] Store loadData() wierd error.

    Hi all,
    I have an issue with the store.loadData() function.

    Firebug, with ScriptMode="Debug", shows me the following error:
    root is undefined
    var root = this.getRoot(o), c = root.length, totalRecords = c, success = true;
    I double checked and it is some code in the JsonReader.js
    Hera an example on how i use the loadData() function.

    The example works fine and i wasn't able to reproduce the bug... so i can't really understand what's wrong with my code! :mad:
    I'm looking for some suggestions.

    <%@ Page Language="C#" %>
    
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    
    <script runat="server">
        
        protected void Button_Click(object sender, DirectEventArgs e)
        {
            X.Msg.Prompt("Name", "Please enter a name:", new JFunction { Fn = "add" }).Show();
        }
    
        
        private static int counter = 0;
        
        [DirectMethod]
        public Data Add(Data data)
        {
            data.Id = counter++;
            return data;
        }
        
        public class Data
        {
            public int Id { get; set; }
            public string Name { get; set; }
        } 
    </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>User FormPanel</title>
        
        <ext:ResourcePlaceHolder runat="server" Mode="Script" />
        
        <script type="text/javascript">
            var add = function (btn, name) {
                var grid = GridPanel;
    
                var record = new grid.store.recordType({
                    Name: name
                });
    
                var addRecord = function (data) {
                    grid.store.loadData(data, true);
                };
    
                Ext.net.DirectMethods.Add(record.data, {
                    success: addRecord,
                    eventMask: {
                        showMask: true,
                        msg: "Updating ..."
                    }
                });
            }
    
        </script>
    </head>
    <body>
        <ext:ResourceManager ID="ResourceManager" runat="server" />
    
        <ext:Store 
            runat="server" 
            ID="Store"
            AutoLoad="false"
            RefreshAfterSaving="Always">
            <Reader>
                <ext:JsonReader IDProperty="Id"> 
                    <Fields>
                        <ext:RecordField Name="Id" Type="Int" />
                        <ext:RecordField Name="Name" Type="String"/>
                    </Fields>
                </ext:JsonReader>
            </Reader>
            <SortInfo Field="Id" Direction="ASC" />
        </ext:Store>     
    
         <ext:GridPanel
            runat="server" 
            ID="GridPanel"
            StoreID="Store"
            Title="Table" 
            Icon="Table"
            Frame="true"
            AutoHeight="true"
            Width="400">
             <ColumnModel ID="ColumnModel1" runat="server">
                 <Columns>
                     <ext:Column Header="ID" DataIndex="Id" ColumnID="id" />
                     <ext:Column Header="Name" DataIndex="Name" ColumnID="name" />
                 </Columns>
             </ColumnModel>
             <SelectionModel>
                <ext:RowSelectionModel runat="server" />
             </SelectionModel>
             <Buttons>
                 <ext:Button runat="server" Text="Add" Icon="Add">
                    <DirectEvents>
                        <Click OnEvent="Button_Click" />
                    </DirectEvents>
                </ext:Button>
             </Buttons>
        </ext:GridPanel>
    
    </body>
    </html>
    Last edited by Daniil; Nov 12, 2010 at 7:36 AM. Reason: Marked as [CLOSED]. No more information was provided.
  2. #2
    Hi,

    Your test sample works correclty, I don't see any errors. The record is added properly
  3. #3
    Hi capecod,

    Could you give some clues how to reproduce it? I have no ideas at the moment what can be wrong.
  4. #4
    Hi,

    In your real application do you any proxy? Do you have Root property? Can you post store from your real application?
  5. #5
        <ext:Store 
            runat="server" 
            ID="UserStore"
            SkipIdForNewRecords="true"
            RefreshAfterSaving="Always"
            OnBeforeRecordUpdated="BeforeUserUpdated"
            OnRefreshData="RefreshUsers">
            <Proxy>
                <ext:PageProxy />
            </Proxy>
            <Reader>
                <ext:JsonReader IDProperty="Id"> 
                    <Fields>
                        <ext:RecordField Name="Id" Type="Int" />
                        <ext:RecordField Name="Username" Type="String"/>
                        <ext:RecordField Name="Nickname" Type="String"/>
                    </Fields>
                </ext:JsonReader>
            </Reader>
            <Listeners>
                <LoadException Fn="onException" />
                <SaveException Fn="onException" />
            </Listeners>
            <SortInfo Field="Id" Direction="ASC" />
        </ext:Store>
  6. #6
    Hi,

    Did you try to reproduce the issue using this Store, not a Store which is used in the example from the initial post?

    As far as I can understand it's rather complicated to reduce your real application to post here simplified version which would reproduce the issue.

    Please remember that you can zip the whole project and post it here (without Ext.Net dlls) or send us via email on support@object.net.
  7. #7
    Hi,

    PageProxy uses "data" as root for the data therefore you have to return your data in the object with "data" property. Also, please note that we should ensure that root is built in the meta (proxy do it automatically for first data request but you should do it manually if data is not loaded yet by proxy)

    Please see the sample
    <%@ Page Language="C#" %>
     
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
     
    <script runat="server">
         
        protected void Button_Click(object sender, DirectEventArgs e)
        {
            X.Msg.Prompt("Name", "Please enter a name:", new JFunction { Fn = "add" }).Show();
        }
        
        private static int counter = 0;
         
        [DirectMethod]
        public object Add(Data data)
        {
            data.Id = counter++;
            return new { data = data };
        }
         
        public class Data
        {
            public int Id { get; set; }
            public string Name { get; set; }
        } 
    </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>User FormPanel</title>
         
        <ext:ResourcePlaceHolder runat="server" Mode="Script" />
         
        <script type="text/javascript">
            var add = function(btn, name) {
                var grid = GridPanel;
    
                var record = new grid.store.recordType({
                    Name: name
                });
    
                var addRecord = function(data) {
                    // need ensure that root is built in the meta
                    // page proxy do it automatically
                    // but we load the data avoid proxy 
                    var meta = grid.store.reader.meta;
                    if (Ext.isEmpty(meta.root)) {
                        meta.root = "data";
                        delete grid.store.reader.ef;
                        grid.store.reader.buildExtractors();
                    }
    
                    grid.store.loadData(data, true);
                };
    
                Ext.net.DirectMethods.Add(record.data, {
                    success: addRecord,
                    eventMask: {
                        showMask: true,
                        msg: "Updating ..."
                    }
                });
            }
     
        </script>
    </head>
    <body>
        <ext:ResourceManager ID="ResourceManager" runat="server" ScriptMode="Debug" />
     
        <ext:Store
            runat="server"
            ID="Store"
            AutoLoad="false"
            RefreshAfterSaving="Always">
            <Proxy>
                <ext:PageProxy />
            </Proxy>
            <Reader>
                <ext:JsonReader IDProperty="Id"> 
                    <Fields>
                        <ext:RecordField Name="Id" Type="Int" />
                        <ext:RecordField Name="Name" Type="String"/>
                    </Fields>
                </ext:JsonReader>
            </Reader>
            <SortInfo Field="Id" Direction="ASC" />
        </ext:Store>     
     
         <ext:GridPanel
            runat="server"
            ID="GridPanel"
            StoreID="Store"
            Title="Table"
            Icon="Table"
            Frame="true"
            AutoHeight="true"
            Width="400">
             <ColumnModel ID="ColumnModel1" runat="server">
                 <Columns>
                     <ext:Column Header="ID" DataIndex="Id" ColumnID="id" />
                     <ext:Column Header="Name" DataIndex="Name" ColumnID="name" />
                 </Columns>
             </ColumnModel>
             <SelectionModel>
                <ext:RowSelectionModel runat="server" />
             </SelectionModel>
             <Buttons>
                 <ext:Button runat="server" Text="Add" Icon="Add">
                    <DirectEvents>
                        <Click OnEvent="Button_Click" />
                    </DirectEvents>
                </ext:Button>
             </Buttons>
        </ext:GridPanel>
     
    </body>
    </html>
  8. #8
    Hi,

    Also, please note that you can always use AddRecord/InsertRecord methods. In this, you don't need to worry about the root
    Store.AddRecord(new Data {Id=1, Name="First"});
  9. #9
    Hi,
    i tried the "meta" fix and didn't worked.
    I think i will send you my project trough mail.

    Thanks ;)
  10. #10
    Hi capecod,

    Seems there is nothing from you at support@object.net. Please clarify did you send anything?

    NOTE: Marked as [CLOSED]. No more information was provided.
    Last edited by Daniil; Nov 12, 2010 at 7:36 AM. Reason: Added note

Similar Threads

  1. [CLOSED] [2.0] Razor and Store LoadData
    By Timothy in forum 2.x Legacy Premium Help
    Replies: 8
    Last Post: Jun 28, 2012, 6:45 PM
  2. Store.loadData()
    By glenh in forum 1.x Help
    Replies: 2
    Last Post: Dec 05, 2011, 3:34 AM
  3. About Ext.Net Store.loadData
    By caoit in forum 1.x Help
    Replies: 0
    Last Post: Apr 26, 2011, 2:41 AM
  4. [1.0] Store.LoadData vs DataBind
    By Kam in forum 1.x Help
    Replies: 1
    Last Post: Apr 19, 2011, 11:00 AM
  5. Ext.Net Store.loadData
    By cleve in forum 1.x Help
    Replies: 4
    Last Post: Jun 29, 2010, 4:19 PM

Tags for this Thread

Posting Permissions