[CLOSED] Clear store fields and grid columns from AjaxEvent

  1. #1

    [CLOSED] Clear store fields and grid columns from AjaxEvent

    Is there a way to clear all store fields and grid columns during an AjaxEvent and then readd fields and columns? *On initial page load, the store and grid do not have any fields/columns. *On treenode click AjaxEvent, it will add fields and columns. *The fields/columns can be different for each treenode. *I want an efficient way to clear all store fields and grid columns before adding new ones. *
  2. #2

    RE: [CLOSED] Clear store fields and grid columns from AjaxEvent

    Hi,

    I'll try to investigate it and create example for you today/tomorrow. Just want to ensure that all work as required
    I'll let you know soon




  3. #3

    RE: [CLOSED] Clear store fields and grid columns from AjaxEvent

    I was just about to ask if anyone had looked at doing the very same thing!
  4. #4

    RE: [CLOSED] Clear store fields and grid columns from AjaxEvent

    Hi,

    Please see the following sample (update from SVN first)
    <%@ Page Language="C#" %>
    
    <%@ Register Assembly="Coolite.Ext.Web" Namespace="Coolite.Ext.Web" TagPrefix="ext" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <script runat="server">
        private void BuildSet1()
        {
            if (Ext.IsAjaxRequest)
            {
                this.Store1.RemoveFields();
                this.Store1.AddField(new RecordField("StringField"));
                this.Store1.AddField(new RecordField("IntField", RecordFieldType.Int));
            }
            else
            {
                this.Store1.Reader.Reader.Fields.Add(new RecordField("StringField"));
                this.Store1.Reader.Reader.Fields.Add(new RecordField("IntField", RecordFieldType.Int));
            }
            
            this.Store1.DataSource = new object[]
                {
                    new object[] {"Set1_1", 1},
                    new object[] {"Set1_2", 2},
                    new object[] {"Set1_3", 3}
                };
    
            this.Store1.DataBind();
            
            this.GridPanel1.ColumnModel.Columns.Add(new Column{DataIndex = "StringField", Header = "String"});
            this.GridPanel1.ColumnModel.Columns.Add(new Column { DataIndex = "IntField", Header = "Int" });
            
            if(Ext.IsAjaxRequest)
            {
                this.GridPanel1.Reconfigure();
            }
        }
    
        private void BuildSet2()
        {
            if (Ext.IsAjaxRequest)
            {
                this.Store1.RemoveFields();
                this.Store1.AddField(new RecordField("IntField1", RecordFieldType.Int));
                this.Store1.AddField(new RecordField("StringField"));
                this.Store1.AddField(new RecordField("IntField2", RecordFieldType.Int));
            }
            else
            {
                this.Store1.Reader.Reader.Fields.Add(new RecordField("IntField1", RecordFieldType.Int));
                this.Store1.Reader.Reader.Fields.Add(new RecordField("StringField"));
                this.Store1.Reader.Reader.Fields.Add(new RecordField("IntField2", RecordFieldType.Int));
            }
            
            this.Store1.DataSource = new object[]
                {
                    new object[] {1, "Set2_1", 1},
                    new object[] {2, "Set2_2", 2},
                    new object[] {3, "Set2_3", 3}
                };
    
            this.Store1.DataBind();
    
            this.GridPanel1.ColumnModel.Columns.Add(new Column { DataIndex = "IntField1", Header = "Int1" });
            this.GridPanel1.ColumnModel.Columns.Add(new Column { DataIndex = "StringField", Header = "String" });
            this.GridPanel1.ColumnModel.Columns.Add(new Column { DataIndex = "IntField2", Header = "Int2" });
    
            if (Ext.IsAjaxRequest)
            {
                this.GridPanel1.Reconfigure();
            }
        }
        
        protected void Page_Load(object sender, EventArgs e)
        {
            if(!Ext.IsAjaxRequest)
            {
                this.BuildSet1();
            }
        }
    
        protected void LoadSet1(object sender, AjaxEventArgs e)
        {
            this.BuildSet1();
        }
    
        protected void LoadSet2(object sender, AjaxEventArgs e)
        {
            this.BuildSet2();
        }
    </script>
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head id="Head1" runat="server">
        <title></title>
    </head>
    <body>
        <form id="form1" runat="server">
            <ext:ScriptManager ID="ScriptManager1" runat="server" />
            
            <ext:Store ID="Store1" runat="server">
                <Reader>
                    <ext:ArrayReader>                    
                    </ext:ArrayReader>
                </Reader>
            </ext:Store>
            
            <ext:GridPanel 
                ID="GridPanel1" 
                runat="server" 
                StoreID="Store1" 
                Title="Grid" 
                Width="600" 
                Height="350">            
                <SelectionModel>
                    <ext:RowSelectionModel ID="RowSelectionModel1" runat="server" SingleSelect="true" />
                </SelectionModel>      
                <Buttons>
                    <ext:Button runat="server" Text="Load Set1">
                        <AjaxEvents>
                            <Click OnEvent="LoadSet1"></Click>
                        </AjaxEvents>
                    </ext:Button>
                    
                    <ext:Button runat="server" Text="Load Set2">
                        <AjaxEvents>
                            <Click OnEvent="LoadSet2"></Click>
                        </AjaxEvents>
                    </ext:Button>
                </Buttons>      
            </ext:GridPanel>          
        </form>
    </body>
    </html>

Similar Threads

  1. Replies: 17
    Last Post: Dec 29, 2012, 6:25 AM
  2. [CLOSED] number fields in grid/columns
    By marco.morreale in forum 2.x Legacy Premium Help
    Replies: 6
    Last Post: May 18, 2012, 5:22 PM
  3. [CLOSED] how to export few columns from grid store to excel?
    By rnachman in forum 1.x Legacy Premium Help
    Replies: 1
    Last Post: Mar 28, 2012, 8:32 PM
  4. [CLOSED] Create dynamic columns grid and store.
    By stoque in forum 1.x Legacy Premium Help
    Replies: 3
    Last Post: Jun 10, 2011, 8:53 PM
  5. Replies: 6
    Last Post: Feb 11, 2009, 3:13 PM

Posting Permissions