[CLOSED] How do you dynamically create and populate a copy of a store in code-behind ?

  1. #1

    [CLOSED] How do you dynamically create and populate a copy of a store in code-behind ?

    Consider the simple store "stoUser" below that is loaded with data.

        <ext:Store ID="stoUser" runat="server" >
            <Model>
                <ext:Model ID="modUser" runat="server">
                    <Fields>
                        <ext:ModelField Name="FirstName" />
                        <ext:ModelField Name="LastName" />
                    </Fields>
                </ext:Model>
            </Model>
         </ext:Store>
    I need to dynamically create a copy of this store in code-behind and copy the data. This is something we were able to in Ext.Net v1. Below is the code I am trying to get to work;

                    var stoCopy = new Ext.Net.Store();
                    stoCopy.ID = "stoCopy";
                    stoCopy.ClientIDMode = ClientIDMode.Static;
     
                    var modCopy = new Ext.Net.Model();
                    modCopy.ID = "modCopy";
                    modCopy.ClientIDMode = ClientIDMode.Static;
                    foreach (ModelField fld in stoUser.Model[0].Fields)
                    {
                        modCopy.Fields.Add(fld);
                    }
     
                    stoCopy.Model.Add(modCopy);
     
                    stoCopy.Listeners.BeforeLoad.Handler += "App.stoCopy.data = App.stoUser.data.clone();";
     
                    Controls.Add(stoCopy);
    Last edited by Daniil; Mar 09, 2014 at 2:42 PM. Reason: [CLOSED]
  2. #2
    Hi @betamax,

    Your code appears to be working to clone an instance of Store and I would load the data in a bit different way.

    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)
            {
                var stoCopy = new Ext.Net.Store();
                stoCopy.ID = "stoCopy";
                var modCopy = new Ext.Net.Model();
                modCopy.ID = "modCopy";
                modCopy.Fields.AddRange(stoUser.Model[0].Fields);
                stoCopy.Model.Add(modCopy);
    
                this.Form.Controls.Add(stoCopy);
            }
        }
    </script>
    
    <!DOCTYPE html>
    <html>
    <head runat="server">
        <title>Ext.NET v2 Example</title>
    </head>
    <body>
        <form runat="server">
            <ext:ResourceManager runat="server" />
           
            <ext:Store ID="stoUser" runat="server" >
                <Model>
                    <ext:Model ID="modUser" runat="server">
                        <Fields>
                            <ext:ModelField Name="FirstName" />
                            <ext:ModelField Name="LastName" />
                        </Fields>
                    </ext:Model>
                </Model>
             </ext:Store>
        </form>
    </body>
    </html>
  3. #3
    Turns out the original example I supplied works, we just had to add a delay to the call to clone.

    stoCopy.Listeners.BeforeLoad.Handler += "App.stoCopy.data = App.stoUser.data.clone().delay(10);";
    Solution found by user MDB
    Thanks, mark as closed
    Last edited by betamax; Mar 07, 2014 at 7:25 PM.

Similar Threads

  1. Create store dynamically from JS code
    By rishu in forum 2.x Help
    Replies: 2
    Last Post: Jul 23, 2013, 12:37 PM
  2. [CLOSED] Problem to create a store in code behind.
    By feanor91 in forum 2.x Legacy Premium Help
    Replies: 2
    Last Post: Jan 24, 2013, 8:14 AM
  3. [CLOSED] How to create and load datasource ( Store ) dynamically in MVC
    By pawangyanwali in forum 2.x Legacy Premium Help
    Replies: 1
    Last Post: Oct 29, 2012, 10:55 AM
  4. Replies: 1
    Last Post: Mar 01, 2012, 2:41 PM
  5. Dynamically create GridPanel and Store
    By whitvanilla in forum 1.x Help
    Replies: 4
    Last Post: Jun 18, 2009, 10:18 PM

Posting Permissions