[CLOSED] Add records with ModelProxy

  1. #1

    [CLOSED] Add records with ModelProxy

    Hi, I want to add many records in a Store, but I have many columns, so, I want to use the object ModelProxy, because I use

    sStore1.Add(new { Col1 = "Col11", Col2 = "Col12" ... Coln = "Col1n" });
    So, It's a long line...

    But, I don't know how to implent this object (ModelProxy), I am beging the example, but the contructor to ModelProxy It has a parameter AbstractStore, Could you please give me an example to ModelProxy in serverside?

            <ext:ResourceManager ID="ResourceManager1" runat="server" />
    
            <ext:ComboBox 
                ID="cmbSucursal"
                runat="server"
                DisplayField="Nombre"
                ValueField="Sucursal">
                <Store>
                    <ext:Store ID="sSucursal" runat="server">
                        <DirectEvents>
                            <Load OnEvent="sSucursal_Load" />
                        </DirectEvents>
                        <Model>
                            <ext:Model ID="mSucursal" runat="server">
                                <Fields>
                                    <ext:ModelField Name="Sucursal" Type="Int" />
                                    <ext:ModelField Name="Nombre" Type="String" />
                                </Fields>
                            </ext:Model>
                        </Model>
                    </ext:Store>
                </Store>
            </ext:ComboBox>
            protected void sSucursal_Load(object sender, DirectEventArgs e)
            {
                for (int i = 0; i < 5; i++)
                    sSucursal.Add(new { Sucursal = i, Nombre = "Nombre" + i });
    
                //Add with ModelProxy other five records
                //ModelProxy mp = new ModelProxy(
            }
    Click image for larger version. 

Name:	ModelProxy.png 
Views:	9 
Size:	14.5 KB 
ID:	7454
    Last edited by Daniil; Jan 14, 2014 at 7:39 AM. Reason: [CLOSED]
  2. #2
    Hi @osef,

    Let's start from the fact that you are trying to add the records in a Store's Load DirectEvent. It looks very weird.

    What about using a Store's DataSource?

    As for a ModelProxy. It is not supposed to be used in the way that you are trying to use it.

    sStore1.Add(new { Col1 = "Col11", Col2 = "Col12" ... Coln = "Col1n" });
    So, It's a long line...
    Could you, please, clarify why it is a problem? And I am not sure how you want to use a ModelProxy to avoid it.
  3. #3
    Quote Originally Posted by Daniil View Post
    Hi @osef,

    Let's start from the fact that you are trying to add the records in a Store's Load DirectEvent. It looks very weird.

    What about using a Store's DataSource?

    As for a ModelProxy. It is not supposed to be used in the way that you are trying to use it.



    Could you, please, clarify why it is a problem? And I am not sure how you want to use a ModelProxy to avoid it.
    Hi Daniil, It's just an example to add records in a Store's Load DirectEvent, Actually I want to add records from Click DirectEvent (Button), The user has a GridPanel where to add records one by one.

    It is ModelProxy a parameter to add records in "Store1.add(ModelProxy mp)" so, there are 3 ways:

    Click image for larger version. 

Name:	Way01.png 
Views:	10 
Size:	2.7 KB 
ID:	7455Click image for larger version. 

Name:	Way02.png 
Views:	9 
Size:	2.5 KB 
ID:	7456Click image for larger version. 

Name:	Way03.png 
Views:	8 
Size:	3.0 KB 
ID:	7457

    So, I want to learn other way to add records in a Store from ServerSide.
  4. #4
    Here is an example.

    To get the Add method with a ModelProxy working, please update from the SVN trunk (revision #5598).

    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 = "test1", 
                        test2 = "test2" 
                    },
                    new 
                    {
                        test1 = "test3", 
                        test2 = "test4" 
                    }
                };
            }
        }
    
        protected void Add1(object sender, DirectEventArgs e)
        {
            Store store = this.GridPanel1.GetStore();
    
            store.Add(new
            {
                test1 = "new1",
                test2 = "new2"
            });
        }
    
        protected void Add2(object sender, DirectEventArgs e)
        {
            Store store = this.GridPanel1.GetStore();
    
            store.Add(new object[] 
            {
                new 
                {
                    test1 = "new3",
                    test2 = "new4"
                },
                new 
                {
                    test1 = "new5",
                    test2 = "new6"
                }
            });
        }
    
        protected void Add3(object sender, DirectEventArgs e)
        {
            Store store1 = this.GridPanel1.GetStore();
            Store store2 = this.GridPanel2.GetStore();
    
            ModelProxy rec = store1.GetAt(1);
            store2.Add(rec);
        }
    </script>
    
    <!DOCTYPE html>
    
    <html>
    <head runat="server">
        <title>Ext.NET v2 Example</title>
    </head>
    <body>
        <form runat="server">
            <ext:ResourceManager runat="server" />
    
            <ext:Button runat="server" Text="Add a record to GridPanel1" OnDirectClick="Add1" />
    
            <ext:Button runat="server" Text="Add several records to GridPanel1" OnDirectClick="Add2" />
    
            <ext:Button runat="server" Text="Add the second record from GridPanel1 to GridPanel2" OnDirectClick="Add3" />
    
            <ext:GridPanel ID="GridPanel1" runat="server"  Title="GridPanel1">
                <Store>
                    <ext:Store runat="server">
                        <Model>
                            <ext:Model runat="server">
                                <Fields>
                                    <ext:ModelField Name="test1" />
                                    <ext:ModelField Name="test2" />
                                </Fields>
                            </ext:Model>
                        </Model>
                    </ext:Store>
                </Store>
                <ColumnModel runat="server">
                    <Columns>
                        <ext:Column runat="server" Text="Test 1" DataIndex="test1" />
                        <ext:Column runat="server" Text="Test 2" DataIndex="test2" />
                    </Columns>
                </ColumnModel>
            </ext:GridPanel>
    
            <br />
    
            <ext:GridPanel ID="GridPanel2" runat="server" Title="GridPanel2">
                <Store>
                    <ext:Store runat="server">
                        <Model>
                            <ext:Model runat="server">
                                <Fields>
                                    <ext:ModelField Name="test1" />
                                    <ext:ModelField Name="test2" />
                                </Fields>
                            </ext:Model>
                        </Model>
                    </ext:Store>
                </Store>
                <ColumnModel runat="server">
                    <Columns>
                        <ext:Column runat="server" Text="Test 1" DataIndex="test1" />
                        <ext:Column runat="server" Text="Test 2" DataIndex="test2" />
                    </Columns>
                </ColumnModel>
            </ext:GridPanel>
        </form>
    </body>
    </html>

Similar Threads

  1. Replies: 7
    Last Post: Mar 25, 2013, 12:02 PM
  2. [CLOSED] too many records
    By tactime10 in forum 2.x Legacy Premium Help
    Replies: 1
    Last Post: Oct 22, 2012, 8:23 AM
  3. Replies: 5
    Last Post: Jun 14, 2011, 11:47 AM
  4. Get Store records
    By walle in forum 1.x Help
    Replies: 4
    Last Post: Jul 17, 2010, 5:19 PM
  5. Replies: 3
    Last Post: Jun 29, 2010, 2:54 PM

Tags for this Thread

Posting Permissions