[CLOSED] Gridpanel: How to insert new row in the gridpanel store

  1. #1

    [CLOSED] Gridpanel: How to insert new row in the gridpanel store

    I have a gridpanel whiwch is filled via its related store.
    I want to add new row to the store so that it will be shown in the gridpanel.
    Someone can help Me?

    [DirectMethod]
            protected void treePanelChecked_Changed(object sender, DirectEventArgs e)
            {
               List<SubmittedNode> selectedNode= ((Ext.Net.TreeSelectionModel)(TreePanel1.GetSelectionModel())).SelectedNodes;
               if (selectedNode != null && selectedNode.Count > 0)
               {
                   SubmittedNode currentNode= selectedNode[0];
                   DTO grd = Lst.FirstOrDefault(g => g.Id.ToString() == currentNode.NodeID);
                   if (!currentNode.Checked)
                   {
                   Store grdstore=GridPanel1.GetStore();
                   grdstore.Insert(0, grd);
                   grdstore.DataBind();
              }
         }
    Last edited by Daniil; Nov 12, 2013 at 9:22 AM. Reason: Please use [CODE] tags, [CLOSED]
  2. #2
    <ext:Store ID="store_act" runat="server" AutoSync="false">
            <Model>
              <ext:Model ID="model_act" runat="server" IDProperty="ACV_ID" Name="ACT">
                  <Fields>
                      <ext:ModelField Name="ACV_ID" Type="Int"  />
                      <ext:ModelField Name="ACV_DATE" Type="Date" />
                      <ext:ModelField Name="ACV_HOURS" Type="Float"/>
    
                  </Fields>
              </ext:Model>
            </Model>
     </ext:Store>

    In Javascript

          var newrow = new ACT({ ACV_DATE: new Date(), ACV_HOURS: 15 });
          newrow.phantom = true;
          App.store_act.insert(0, newrow);
  3. #3
    Quote Originally Posted by mtsig View Post
    <ext:Store ID="store_act" runat="server" AutoSync="false">
            <Model>
              <ext:Model ID="model_act" runat="server" IDProperty="ACV_ID" Name="ACT">
                  <Fields>
                      <ext:ModelField Name="ACV_ID" Type="Int"  />
                      <ext:ModelField Name="ACV_DATE" Type="Date" />
                      <ext:ModelField Name="ACV_HOURS" Type="Float"/>
    
                  </Fields>
              </ext:Model>
            </Model>
     </ext:Store>

    In Javascript

          var newrow = new ACT({ ACV_DATE: new Date(), ACV_HOURS: 15 });
          newrow.phantom = true;
          App.store_act.insert(0, newrow);
    I do it in codebehind using directEvent
    Is there a solution using codebehind C# Code?
  4. #4
    Hi @AdminAISN,

    Welcome to the Ext.NET forum!

    I think you should remove this:
    grdstore.DataBind();
    It is uses a Store's DataSource which you are not setting up. So, the Store is bound with no data erasing an added record by the Insert call.

    @mtsig, thank you for answering! Much appreciated.
  5. #5
    Quote Originally Posted by AdminAISN View Post
    I have a gridpanel whiwch is filled via its related store.
    I want to add new row to the store so that it will be shown in the gridpanel.
    Someone can help Me?

    [DirectMethod]
            protected void treePanelChecked_Changed(object sender, DirectEventArgs e)
            {
               List<SubmittedNode> selectedNode= ((Ext.Net.TreeSelectionModel)(TreePanel1.GetSelectionModel())).SelectedNodes;
               if (selectedNode != null && selectedNode.Count > 0)
               {
                   SubmittedNode currentNode= selectedNode[0];
                   DTO grd = Lst.FirstOrDefault(g => g.Id.ToString() == currentNode.NodeID);
                   if (!currentNode.Checked)
                   {
                   Store grdstore=GridPanel1.GetStore();
                   grdstore.Insert(0, grd);
                   grdstore.DataBind();
              }
         }
    I tried but unfortunetly it doesn't work. I was obliged to rebuild the datasource. Perhaps somebody will gie me an help.
    Thx.
  6. #6
    Hello!

    Couldn't reproduce with the following sample:

    <%@ 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)
            {
                this.Store1.DataSource = this.Data;
                this.Store1.DataBind();
            }
        }
    
        protected void AddRecord(object sender, DirectEventArgs e)
        {
            Store1.Insert(0,  new { company = "3m Co", price = 71.72, change = 0.02, pctChange = 0.03, lastChange = "9/1 12:00am" });
        }
    
        private object[] Data
        {
            get
            {
                return new object[]
                {
                    new object[] { "Alcoa Inc", 29.01, 0.42, 1.47, "9/1 12:00am" },
                    new object[] { "Altria Group Inc", 83.81, 0.28, 0.34, "9/1 12:00am" },
                    new object[] { "American Express Company", 52.55, 0.01, 0.02, "9/1 12:00am" },
                    new object[] { "American International Group, Inc.", 64.13, 0.31, 0.49, "9/1 12:00am" },
                    new object[] { "AT&T Inc.", 31.61, -0.48, -1.54, "9/1 12:00am" },
                    new object[] { "Boeing Co.", 75.43, 0.53, 0.71, "9/1 12:00am" }
                };
            }
        }
    </script>
    
    <!DOCTYPE html>
    
    <html>
    <head id="Head1" runat="server">
    </head>
    <body>
        <ext:ResourceManager ID="ResourceManager1" runat="server" />
        
        <h1>Simple Array Grid</h1>
        
        <ext:GridPanel 
            ID="GridPanel1"
            runat="server" 
            Title="Array Grid" 
            Width="600" 
            Height="350">
            <Store>
                <ext:Store ID="Store1" runat="server">
                    <Model>
                        <ext:Model ID="Model1" runat="server">
                            <Fields>
                                <ext:ModelField Name="company" />
                                <ext:ModelField Name="price" Type="Float" />
                                <ext:ModelField Name="change" Type="Float" />
                                <ext:ModelField Name="pctChange" Type="Float" />
                                <ext:ModelField Name="lastChange" Type="Date" DateFormat="M/d hh:mmtt" />
                            </Fields>
                        </ext:Model>
                    </Model>
                    <Reader>
                        <ext:ArrayReader />
                    </Reader>
                </ext:Store>
            </Store>
            <ColumnModel>
                <Columns>
                    <ext:Column ID="Column1" runat="server" Text="Company" DataIndex="company" Flex="1" />
                    <ext:Column ID="Column2" runat="server" Text="Price" DataIndex="price">                  
                    </ext:Column>
                    <ext:Column ID="Column3" runat="server" Text="Change" DataIndex="change">
                    </ext:Column>
                    <ext:Column ID="Column4" runat="server" Text="Change" DataIndex="pctChange">
                    </ext:Column>
                    <ext:DateColumn ID="DateColumn1" runat="server" Text="Last Updated" DataIndex="lastChange" />
                </Columns>            
            </ColumnModel>       
            <SelectionModel>
                <ext:RowSelectionModel ID="RowSelectionModel1" runat="server" />
            </SelectionModel>
            <BottomBar>
                <ext:Toolbar ID="Toolbar1" runat="server">
                    <Items>
                        <ext:Button Text="Add a record">
                            <DirectEvents>
                                <Click OnEvent="AddRecord" />
                            </DirectEvents>
                        </ext:Button>
                    </Items>
                </ext:Toolbar>
            </BottomBar>
        </ext:GridPanel>
    </body>
    </html>
    If it doesn't help please provide sample to reproduce according to these recommendations:
    http://forums.ext.net/showthread.php?3440
    http://forums.ext.net/showthread.php?10205

Similar Threads

  1. [CLOSED] gridpanel with paging - Insert row
    By PriceRightHTML5team in forum 2.x Legacy Premium Help
    Replies: 5
    Last Post: Oct 04, 2013, 5:47 AM
  2. [CLOSED] Insert Rows in GridPanel
    By osef in forum 2.x Legacy Premium Help
    Replies: 4
    Last Post: Sep 11, 2012, 4:38 PM
  3. Replies: 2
    Last Post: Feb 18, 2012, 1:57 AM
  4. insert records in gridpanel
    By pankaj in forum 1.x Help
    Replies: 0
    Last Post: Apr 01, 2010, 5:53 AM
  5. GridPanel - Always have insert/add/new row show
    By Tbaseflug in forum 1.x Help
    Replies: 0
    Last Post: Feb 19, 2009, 11:34 AM

Posting Permissions