Empty rows when dynamically changing Store and Grid columns

  1. #1

    Empty rows when dynamically changing Store and Grid columns

    Hi,

    I am trying to dynamically changes the contents of my grid by reloading the store and recreating the columns in the grid. I'm almost there, but for one of the views, the grid columns change correctly, but the rows aren't loading. I included a simplified scenario to demonstrate. Any ideas? Thanks in advance.

    client side:
    <head runat="server">
        <title>Untitled Page</title>
        
            <script runat="server">
            
            public void RefreshMe1()
            {
                RefreshGrid(1);
            }
            public void RefreshMe2()
            {
                RefreshGrid(2);
            }
                
        </script>
    
    </head>
    <body>
        <form id="form1" runat="server">
        <ext:ScriptManager ID="ScriptManager1" runat="server" />
        
        
        <ext:Store runat="server" ID="Store1" AutoLoad="true">
        </ext:Store>
        
    
        <ext:GridPanel runat="server" ID="GridPanel1" StoreID="Store1" height="300" Width="600" >
        </ext:GridPanel>
        <ext:Button ID="Button1" runat="server" Text="Store1">
             <AjaxEvents>
                <Click OnEvent="Button1_Click"></Click>
            </AjaxEvents> 
        </ext:Button>
        <ext:Button ID="Button2" runat="server" Text="Store2">
               <AjaxEvents>
                <Click OnEvent="Button2_Click"></Click>
            </AjaxEvents> 
        </ext:Button>
        
        </form>
    
    
    </body>

    code behind:
            protected void Page_Load(object sender, EventArgs e)
            {
    
                if (!Ext.IsAjaxRequest)
                {
                    RefreshGrid(1);
                }
    
            }
    
            protected void RefreshGrid(int view)
            {
                ArrayReader testReader = new ArrayReader();
    
                ClearColumns();
                if (Store1.Reader.Count > 0) Store1.Reader.Clear();
                
                if (view == 1)
                {
                    Column newCol = new Column();
                    newCol.DataIndex = "name";
                    newCol.Header = "Name";
                    GridPanel1.ColumnModel.Columns.Add(newCol);
    
                    newCol = new Column();
                    newCol.DataIndex = "value";
                    newCol.Header = "Value";
                    GridPanel1.ColumnModel.Columns.Add(newCol);
    
                    GridPanel1.Reconfigure();
    
                    this.Store1.DataSource = new object[]
                    {
                    new object[] {"Age Determination", "Age Nearest"},
                    new object[] {"Allow Reentry", "End of 10th Year"},
                    new object[] {"Years Level", "10"},
                    new object[] {"Years Guaranteed", "10"},
                    new object[] {"Modal Policy Fee", "$85"},
                    new object[] {"Min/Max Face Amount", "$100,000/$25,000,000"},
                    new object[] {"Min/Max Premium", "$25/$25,000"},
                    new object[] {"Conversion Option", "End of 10th Year"},
                    new object[] {"Policy Maturity Age", "99"},
                    new object[] {"Min/Max Issue Age", "18/69"},
                    new object[] {"Semi-Annual Rate", ".52"},
                    new object[] {"Quarterly Rate", ".27"},
                    new object[] {"Monthly Bank Draft Rate", ".089"},
                    new object[] {"Rate Card Id", "Version 4/1/06"},
                    new object[] {"Software Version", "2.81"},
                    new object[] {"Policy Form Number", "92-SR71"}
                    };
    
                    RecordField aField = new RecordField("name");
                    testReader.Fields.Add(aField);
    
                    aField = new RecordField("value");
                    testReader.Fields.Add(aField);
    
                }
                else
                {
    
                    Column newCol = new Column();
                    newCol.DataIndex = "idx";
                    newCol.Header = "Index";
                    GridPanel1.ColumnModel.Columns.Add(newCol);
    
                    newCol = new Column();
                    newCol.DataIndex = "report";
                    newCol.Header = "Report";
                    GridPanel1.ColumnModel.Columns.Add(newCol);
    
                    newCol = new Column();
                    newCol.DataIndex = "num";
                    newCol.Header = "Number";
                    GridPanel1.ColumnModel.Columns.Add(newCol); 
    
                    newCol = new Column();
                    newCol.DataIndex = "rtype";
                    newCol.Header = "Type";
                    GridPanel1.ColumnModel.Columns.Add(newCol);
    
                    GridPanel1.Reconfigure();
    
                    this.Store1.DataSource = new object[]
                    { 
                     new object[] {"0", "Cover Page", "n/a", "Individual Reports"},
                     new object[] {"1", "Best Of Multi", "8", "Individual Reports"},
                     new object[] {"2", "Best of Years Level", "8", "Individual Reports"},
                     new object[] {"3", "Classic (All Products)", "All", "Individual Reports"},
                     new object[] {"4", "Classic (Best 6)", "6", "Individual Reports"},
                     new object[] {"5", "Classic (Best 8)", "8", "Individual Reports"},
                     new object[] {"6", "Classic (Best 11)", "11", "Individual Reports"},
                     new object[] {"7", "Classic w/Modals (Best 6)", "6", "Individual Reports"},
                     new object[] {"8", "Classic w/Modals (Best 8)", "8", "Individual Reports"},
                     new object[] {"9", "Classic w/Modals (Best 11)", "11", "Individual Reports"},
                     new object[] {"10", "Features w/Modals (Prods 1-4)", "4", "Individual Reports"},
                     new object[] {"11", "Features w/Modals (Prods 5-8)", "4", "Individual Reports"},
                     new object[] {"12", "Narratives (Best 8)", "8", "Individual Reports"},
                     new object[] {"13", "Quick 1st Year", "All", "Individual Reports"},
                     new object[] {"14", "Disclaimer", "n/a", "Individual Reports"},
                     new object[] {"15", "VitalSigns (Profile)", "1", "Individual Reports"},
                     new object[] {"16", "VitalSigns (Analysis)", "1", "Individual Reports"},
                     new object[] {"17", "VitalSigns (Snapshot)", "1", "Individual Reports"},
                     new object[] {"18", "VitalSigns (Ratings)", "1", "Individual Reports"},
                     new object[] {"18", "Std Package 1", "n/a", "Custom Packages"},
                     new object[] {"19", "Std Package 2", "n/a", "Custom Packages"},
                     new object[] {"20", "Profile Suite", "n/a", "Custom Packages"},
                     new object[] {"21", "Quick Draft", "n/a", "Custom Packages"},
                    };
     
                    RecordField aField = new RecordField("idx");
                    testReader.Fields.Add(aField);
    
                    aField = new RecordField("report");
                    testReader.Fields.Add(aField);
    
                    aField = new RecordField("num");
                    testReader.Fields.Add(aField);
    
                    aField = new RecordField("rtype");
                    testReader.Fields.Add(aField);
    
                }
                Store1.Reader.Add(testReader);
                Store1.DataBind();
            }
    
            private void ClearColumns()
            {
                for (int i = GridPanel1.ColumnModel.Columns.Count; i < 0; i--)
                {
                    GridPanel1.ColumnModel.Columns.Remove(GridPanel1.ColumnModel.Columns[i]);
                }
            }
    
            protected void Button1_Click(object sender, AjaxEventArgs e)
            {
                RefreshGrid(1);
            }
    
            protected void Button2_Click(object sender, AjaxEventArgs e)
            {
                RefreshGrid(2);
            }
  2. #2

    RE: Empty rows when dynamically changing Store and Grid columns

    Hi,

    The Reader must be specified in initial page load (you can't add it during ajax event) . All store fields and grid panel should use special functions when adding during ajax event (AddField and AddColumn).
    Please see example*https://examples1.ext.net/#/GridPanel/ColumnModel/Reconfigure/


  3. #3

    RE: Empty rows when dynamically changing Store and Grid columns

    Thanks for the example,* however I am still a little confused.

    The example is only one datasource and I am using 2.* How / where in my sample would I create the datasources and set them to the reader?* I noticed that the Store's reader is placed in a ReaderCollection.* Is there an example out there that uses more than one reader in the collection to load data in a GridPanel?*

    Also, I don't see Store.AddField in my autocomplete nor will it compile if I change it anyway.** Is this new method for 0.8.0?

  4. #4

    RE: Empty rows when dynamically changing Store and Grid columns

    Hi,

    Yes, AddField is introduced in 0.8.0


    May be it is better to have two store on page without data. Then you can change store for grid and reload store *(you can change grid generate script GridPanel1.AddScript("{0}.store = {1};{1}.reload();", GridPanel1.ClientID, Store1.ClientID); )


  5. #5

    RE: Empty rows when dynamically changing Store and Grid columns

    *Thanks.* I see that 2 stores might reduce the hassle.* I set up 2 stores (Store1 and Store2), loaded and bound them at page load, then added a script for each option = (load Store1 to grid, load Store2 to grid).* If I use GridPanel.AddColumn(), I get an empty grid with no column headers, if I use GridPanel1.ColumnModel.Columns.Add();* I get no rows, but column headers.* I know you said I need to use AddColumns, is there something else wrong with how I am doing it?* Or a bug fix for 0.8.0 that I need to wait on?* If its a fix in 0.8.0, I can work on getting a premium subscription paid for thru my corporate office.* Here's my reworked code below.* Thanks.

    client side (inside body tags):
    *** <form id="form1" runat="server">
    *** <ext:ScriptManager ID="ScriptManager1" runat="server" />
    *** 
    *** 
    *** <ext:Store runat="server" ID="Store1" AutoLoad="true">
    ***** <Reader>
    ******** <ext:ArrayReader>
    ************ <Fields>
    *************** <ext:RecordField Name="name" />
    *************** <ext:RecordField Name="value" />
    ************ </Fields>
    ******** </ext:ArrayReader>
    ***** </Reader>
    *** </ext:Store>
    *** 
    *** <ext:Store runat="server" ID="Store2" AutoLoad="true">
    ***** <Reader>
    ******** <ext:ArrayReader>
    ************ <Fields>
    *************** <ext:RecordField Name="idx" />
    *************** <ext:RecordField Name="report" />
    *************** <ext:RecordField Name="num" />
    *************** <ext:RecordField Name="rtype" />
    ************ </Fields>
    ******** </ext:ArrayReader>
    ***** </Reader>
    *** </ext:Store>
    *** 
    *** <ext:GridPanel runat="server" ID="GridPanel1" StoreID="Store1" height="300" Width="600" >
    *** </ext:GridPanel>
    *** 
    *** <ext:Button ID="Button1" runat="server" Text="Store1">
    ******** <AjaxEvents>
    *********** <Click OnEvent="Button1_Click"></Click>
    ******* </AjaxEvents> 
    *** </ext:Button>
    *** <ext:Button ID="Button2" runat="server" Text="Store2">
    ********** <AjaxEvents>
    *********** <Click OnEvent="Button2_Click"></Click>
    ******* </AjaxEvents> 
    *** </ext:Button>
    *** 
    *** </form>

    code behind
    ******* protected void Page_Load(object sender, EventArgs e)
    ******* {
    
    *********** if (!Ext.IsAjaxRequest)
    *********** {
    *************** this.Store1.DataSource = new object[]
    *************** {
    *************** new object[] {"Age Determination", "Age Nearest"},
    *************** new object[] {"Allow Reentry", "End of 10th Year"},
    *************** new object[] {"Years Level", "10"},
    *************** new object[] {"Years Guaranteed", "10"},
    *************** new object[] {"Modal Policy Fee", "$85"},
    *************** new object[] {"Min/Max Face Amount", "$100,000/$25,000,000"},
    *************** new object[] {"Min/Max Premium", "$25/$25,000"},
    *************** new object[] {"Conversion Option", "End of 10th Year"},
    *************** new object[] {"Policy Maturity Age", "99"},
    *************** new object[] {"Min/Max Issue Age", "18/69"},
    *************** new object[] {"Semi-Annual Rate", ".52"},
    *************** new object[] {"Quarterly Rate", ".27"},
    *************** new object[] {"Monthly Bank Draft Rate", ".089"},
    *************** new object[] {"Rate Card Id", "Version 4/1/06"},
    *************** new object[] {"Software Version", "2.81"},
    *************** new object[] {"Policy Form Number", "92-SR71"}
    *************** };
    
    *************** this.Store1.DataBind();
    
    *************** this.Store2.DataSource = new object[]
    *************** { 
    **************** new object[] {"0", "Cover Page", "n/a", "Individual Reports"},
    **************** new object[] {"1", "Best Of Multi", "8", "Individual Reports"},
    **************** new object[] {"2", "Best of Years Level", "8", "Individual Reports"},
    **************** new object[] {"3", "Classic (All Products)", "All", "Individual Reports"},
    **************** new object[] {"4", "Classic (Best 6)", "6", "Individual Reports"},
    **************** new object[] {"5", "Classic (Best 8)", "8", "Individual Reports"},
    **************** new object[] {"6", "Classic (Best 11)", "11", "Individual Reports"},
    **************** new object[] {"7", "Classic w/Modals (Best 6)", "6", "Individual Reports"},
    **************** new object[] {"8", "Classic w/Modals (Best 8)", "8", "Individual Reports"},
    **************** new object[] {"9", "Classic w/Modals (Best 11)", "11", "Individual Reports"},
    **************** new object[] {"10", "Features w/Modals (Prods 1-4)", "4", "Individual Reports"},
    **************** new object[] {"11", "Features w/Modals (Prods 5-8)", "4", "Individual Reports"},
    **************** new object[] {"12", "Narratives (Best 8)", "8", "Individual Reports"},
    **************** new object[] {"13", "Quick 1st Year", "All", "Individual Reports"},
    **************** new object[] {"14", "Disclaimer", "n/a", "Individual Reports"},
    **************** new object[] {"15", "VitalSigns (Profile)", "1", "Individual Reports"},
    **************** new object[] {"16", "VitalSigns (Analysis)", "1", "Individual Reports"},
    **************** new object[] {"17", "VitalSigns (Snapshot)", "1", "Individual Reports"},
    **************** new object[] {"18", "VitalSigns (Ratings)", "1", "Individual Reports"},
    **************** new object[] {"18", "Std Package 1", "n/a", "Custom Packages"},
    **************** new object[] {"19", "Std Package 2", "n/a", "Custom Packages"},
    **************** new object[] {"20", "Profile Suite", "n/a", "Custom Packages"},
    **************** new object[] {"21", "Quick Draft", "n/a", "Custom Packages"},
    *************** };
    
    *************** this.Store2.DataBind();
    
    ************ }
    
    ******* }
    
    ******* protected void RefreshGrid(int view)
    ******* {
    *********** ArrayReader testReader = new ArrayReader();
    
    *********** ClearColumns();
    *********** 
    *********** if (view == 1)
    *********** {
    *************** Column newCol = new Column();
    *************** newCol.DataIndex = "name";
    *************** newCol.Header = "Name";
    *************** GridPanel1.ColumnModel.Columns.Add(newCol);
    
    *************** newCol = new Column();
    *************** newCol.DataIndex = "value";
    *************** newCol.Header = "Value";
    *************** GridPanel1.ColumnModel.Columns.Add(newCol);
    
    *************** GridPanel1.Reconfigure();
    
    *************** GridPanel1.AddScript("{0}.store = {1};{1}.reload();", GridPanel1.ClientID, Store1.ClientID);
    
    
    *********** }
    *********** else
    *********** {
    
    *************** Column newCol = new Column();
    *************** newCol.DataIndex = "idx";
    *************** newCol.Header = "Index";
    *************** GridPanel1.AddColumn(newCol);
    
    *************** newCol = new Column();
    *************** newCol.DataIndex = "report";
    *************** newCol.Header = "Report";
    *************** GridPanel1.AddColumn(newCol);
    
    *************** newCol = new Column();
    *************** newCol.DataIndex = "num";
    *************** newCol.Header = "Number";
    *************** GridPanel1.AddColumn(newCol);
    
    *************** newCol = new Column();
    *************** newCol.DataIndex = "rtype";
    *************** newCol.Header = "Type";
    *************** GridPanel1.AddColumn(newCol);
    
    *************** GridPanel1.Reconfigure();
    
    *************** GridPanel1.AddScript("{0}.store = {1};{1}.reload();", GridPanel1.ClientID, Store2.ClientID);
    
    
    *********** }
    ******* }
    
    ******* private void ClearColumns()
    ******* {
    *********** for (int i = GridPanel1.ColumnModel.Columns.Count; i < 0; i--)
    *********** {
    *************** GridPanel1.ColumnModel.Columns.Remove(GridPanel1.ColumnModel.Columns[i]);
    *********** }
    ******* }
    
    ******* protected void Button1_Click(object sender, AjaxEventArgs e)
    ******* {
    *********** RefreshGrid(1);
    ******* }
    
    ******* protected void Button2_Click(object sender, AjaxEventArgs e)
    ******* {
    *********** RefreshGrid(2);
    ******* }
  6. #6

    RE: Empty rows when dynamically changing Store and Grid columns

    Vladsch,

    I got it working in my example code... I took out the {1}.reload in the script I added, also moved the Reconfigure() below the addscript(), and Voila! I can toggle between the grid views (w/different stores) with no problem.

    Thanks for your help.
  7. #7

    RE: Empty rows when dynamically changing Store and Grid columns

    Hi,

    AddColumn need use only if add column to existing columns. If you use Reconfigure then you should manipulate with Columns collection (Add method) .

    I changed your example and made two version: with load stores on page load and with lazy load stores (on button click)

    1. AutoLoad stores
    <%@ Page Language="C#" %>
    <%@ Import Namespace="System.Collections.Generic" %>
    
    <%@ 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">
        protected void Page_Load(object sender, EventArgs e)
        {
    
            if (!Ext.IsAjaxRequest)
            {
                this.Store1.DataSource = new object[]
                    {
                    new object[] {"Age Determination", "Age Nearest"},
                    new object[] {"Allow Reentry", "End of 10th Year"},
                    new object[] {"Years Level", "10"},
                    new object[] {"Years Guaranteed", "10"},
                    new object[] {"Modal Policy Fee", "$85"},
                    new object[] {"Min/Max Face Amount", "$100,000/$25,000,000"},
                    new object[] {"Min/Max Premium", "$25/$25,000"},
                    new object[] {"Conversion Option", "End of 10th Year"},
                    new object[] {"Policy Maturity Age", "99"},
                    new object[] {"Min/Max Issue Age", "18/69"},
                    new object[] {"Semi-Annual Rate", ".52"},
                    new object[] {"Quarterly Rate", ".27"},
                    new object[] {"Monthly Bank Draft Rate", ".089"},
                    new object[] {"Rate Card Id", "Version 4/1/06"},
                    new object[] {"Software Version", "2.81"},
                    new object[] {"Policy Form Number", "92-SR71"}
                    };
    
                this.Store1.DataBind();
    
                this.Store2.DataSource = new object[]
                    { 
                     new object[] {"0", "Cover Page", "n/a", "Individual Reports"},
                     new object[] {"1", "Best Of Multi", "8", "Individual Reports"},
                     new object[] {"2", "Best of Years Level", "8", "Individual Reports"},
                     new object[] {"3", "Classic (All Products)", "All", "Individual Reports"},
                     new object[] {"4", "Classic (Best 6)", "6", "Individual Reports"},
                     new object[] {"5", "Classic (Best 8)", "8", "Individual Reports"},
                     new object[] {"6", "Classic (Best 11)", "11", "Individual Reports"},
                     new object[] {"7", "Classic w/Modals (Best 6)", "6", "Individual Reports"},
                     new object[] {"8", "Classic w/Modals (Best 8)", "8", "Individual Reports"},
                     new object[] {"9", "Classic w/Modals (Best 11)", "11", "Individual Reports"},
                     new object[] {"10", "Features w/Modals (Prods 1-4)", "4", "Individual Reports"},
                     new object[] {"11", "Features w/Modals (Prods 5-8)", "4", "Individual Reports"},
                     new object[] {"12", "Narratives (Best 8)", "8", "Individual Reports"},
                     new object[] {"13", "Quick 1st Year", "All", "Individual Reports"},
                     new object[] {"14", "Disclaimer", "n/a", "Individual Reports"},
                     new object[] {"15", "VitalSigns (Profile)", "1", "Individual Reports"},
                     new object[] {"16", "VitalSigns (Analysis)", "1", "Individual Reports"},
                     new object[] {"17", "VitalSigns (Snapshot)", "1", "Individual Reports"},
                     new object[] {"18", "VitalSigns (Ratings)", "1", "Individual Reports"},
                     new object[] {"18", "Std Package 1", "n/a", "Custom Packages"},
                     new object[] {"19", "Std Package 2", "n/a", "Custom Packages"},
                     new object[] {"20", "Profile Suite", "n/a", "Custom Packages"},
                     new object[] {"21", "Quick Draft", "n/a", "Custom Packages"},
                    };
    
                this.Store2.DataBind();
    
            }
    
        }
    
        protected void RefreshGrid(int view)
        {
            ArrayReader testReader = new ArrayReader();
    
            ClearColumns();
    
            if (view == 1)
            {
                
                Column newCol = new Column();
                newCol.DataIndex = "name";
                newCol.Header = "Name";
                GridPanel1.ColumnModel.Columns.Add(newCol);
    
                newCol = new Column();
                newCol.DataIndex = "value";
                newCol.Header = "Value";
                GridPanel1.ColumnModel.Columns.Add(newCol);
    
                GridPanel1.Reconfigure();
    
                GridPanel1.AddScript("{0}.store = {1};{0}.view.refresh(true);", GridPanel1.ClientID, Store1.ClientID);
    
            }
            else
            {
                
                Column newCol = new Column();
                newCol.DataIndex = "idx";
                newCol.Header = "Index";
                GridPanel1.ColumnModel.Columns.Add(newCol);
    
                newCol = new Column();
                newCol.DataIndex = "report";
                newCol.Header = "Report";
                GridPanel1.ColumnModel.Columns.Add(newCol);
    
                newCol = new Column();
                newCol.DataIndex = "num";
                newCol.Header = "Number";
                GridPanel1.ColumnModel.Columns.Add(newCol);
    
                newCol = new Column();
                newCol.DataIndex = "rtype";
                newCol.Header = "Type";
                GridPanel1.ColumnModel.Columns.Add(newCol);
    
                GridPanel1.Reconfigure();
    
                GridPanel1.AddScript("{0}.store = {1};{0}.view.refresh(true);", GridPanel1.ClientID, Store2.ClientID);
    
    
            }
        }
    
        private void ClearColumns()
        {
            GridPanel1.ColumnModel.Columns.Clear();
        }
    
        protected void Button1_Click(object sender, AjaxEventArgs e)
        {
            RefreshGrid(1);
        }
    
        protected void Button2_Click(object sender, AjaxEventArgs e)
        {
            RefreshGrid(2);
        }
    </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" ScriptMode="Debug" />
           
           <ext:Store runat="server" ID="EmptyStore" AutoLoad="false">        
           </ext:Store>
    
           <ext:Store runat="server" ID="Store1" AutoLoad="true">
              <Reader>
                 <ext:ArrayReader>
                     <Fields>
                        <ext:RecordField Name="name" />
                        <ext:RecordField Name="value" />
                     </Fields>
                 </ext:ArrayReader>
              </Reader>
            </ext:Store>
            
            <ext:Store runat="server" ID="Store2" AutoLoad="true">
              <Reader>
                 <ext:ArrayReader>
                     <Fields>
                        <ext:RecordField Name="idx" />
                        <ext:RecordField Name="report" />
                        <ext:RecordField Name="num" />
                        <ext:RecordField Name="rtype" />
                     </Fields>
                 </ext:ArrayReader>
              </Reader>
            </ext:Store>
            
            <ext:GridPanel runat="server" ID="GridPanel1" height="300" Width="600" StoreID="EmptyStore" >
            </ext:GridPanel>
            
            <ext:Button ID="Button1" runat="server" Text="Store1">
                 <AjaxEvents>
                    <Click OnEvent="Button1_Click"></Click>
                </AjaxEvents> 
            </ext:Button>
            <ext:Button ID="Button2" runat="server" Text="Store2">
                   <AjaxEvents>
                    <Click OnEvent="Button2_Click"></Click>
                </AjaxEvents> 
            </ext:Button>
        
        </form>
    </body>
    </html>

    2. Lazy load stores
    <%@ Page Language="C#" %>
    <%@ Import Namespace="System.Collections.Generic" %>
    
    <%@ 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">
        protected void Page_Load(object sender, EventArgs e)
        {
        }
    
        protected void RefreshGrid(int view)
        {
            ArrayReader testReader = new ArrayReader();
    
            ClearColumns();
    
            if (view == 1)
            {
                
                Column newCol = new Column();
                newCol.DataIndex = "name";
                newCol.Header = "Name";
                GridPanel1.ColumnModel.Columns.Add(newCol);
    
                newCol = new Column();
                newCol.DataIndex = "value";
                newCol.Header = "Value";
                GridPanel1.ColumnModel.Columns.Add(newCol);
    
                GridPanel1.Reconfigure();
    
                GridPanel1.AddScript("{0}.store = {1};{0}.view.refresh(true);", GridPanel1.ClientID, Store1.ClientID);
    
            }
            else
            {
                
                Column newCol = new Column();
                newCol.DataIndex = "idx";
                newCol.Header = "Index";
                GridPanel1.ColumnModel.Columns.Add(newCol);
    
                newCol = new Column();
                newCol.DataIndex = "report";
                newCol.Header = "Report";
                GridPanel1.ColumnModel.Columns.Add(newCol);
    
                newCol = new Column();
                newCol.DataIndex = "num";
                newCol.Header = "Number";
                GridPanel1.ColumnModel.Columns.Add(newCol);
    
                newCol = new Column();
                newCol.DataIndex = "rtype";
                newCol.Header = "Type";
                GridPanel1.ColumnModel.Columns.Add(newCol);
    
                GridPanel1.Reconfigure();
    
                GridPanel1.AddScript("{0}.store = {1};{0}.view.refresh(true);", GridPanel1.ClientID, Store2.ClientID);
    
    
            }
        }
    
        private void ClearColumns()
        {
            GridPanel1.ColumnModel.Columns.Clear();
        }
    
        protected void Button1_Click(object sender, AjaxEventArgs e)
        {
            RefreshGrid(1);
    
            //if data is static then you can bind only once
            if (bool.Parse(e.ExtraParams["Rebind"]))
            {
                this.Store1.DataSource = new object[]
                     {
                         new object[] {"Age Determination", "Age Nearest"},
                         new object[] {"Allow Reentry", "End of 10th Year"},
                         new object[] {"Years Level", "10"},
                         new object[] {"Years Guaranteed", "10"},
                         new object[] {"Modal Policy Fee", "$85"},
                         new object[] {"Min/Max Face Amount", "$100,000/$25,000,000"},
                         new object[] {"Min/Max Premium", "$25/$25,000"},
                         new object[] {"Conversion Option", "End of 10th Year"},
                         new object[] {"Policy Maturity Age", "99"},
                         new object[] {"Min/Max Issue Age", "18/69"},
                         new object[] {"Semi-Annual Rate", ".52"},
                         new object[] {"Quarterly Rate", ".27"},
                         new object[] {"Monthly Bank Draft Rate", ".089"},
                         new object[] {"Rate Card Id", "Version 4/1/06"},
                         new object[] {"Software Version", "2.81"},
                         new object[] {"Policy Form Number", "92-SR71"}
                     };
    
                this.Store1.DataBind();
            }
        }
    
        protected void Button2_Click(object sender, AjaxEventArgs e)
        {
            RefreshGrid(2);
            
            //if data is static then you can bind only once
            if (bool.Parse(e.ExtraParams["Rebind"]))
            {
                this.Store2.DataSource = new object[]
                     {
                         new object[] {"0", "Cover Page", "n/a", "Individual Reports"},
                         new object[] {"1", "Best Of Multi", "8", "Individual Reports"},
                         new object[] {"2", "Best of Years Level", "8", "Individual Reports"},
                         new object[] {"3", "Classic (All Products)", "All", "Individual Reports"},
                         new object[] {"4", "Classic (Best 6)", "6", "Individual Reports"},
                         new object[] {"5", "Classic (Best 8)", "8", "Individual Reports"},
                         new object[] {"6", "Classic (Best 11)", "11", "Individual Reports"},
                         new object[] {"7", "Classic w/Modals (Best 6)", "6", "Individual Reports"},
                         new object[] {"8", "Classic w/Modals (Best 8)", "8", "Individual Reports"},
                         new object[] {"9", "Classic w/Modals (Best 11)", "11", "Individual Reports"},
                         new object[] {"10", "Features w/Modals (Prods 1-4)", "4", "Individual Reports"},
                         new object[] {"11", "Features w/Modals (Prods 5-8)", "4", "Individual Reports"},
                         new object[] {"12", "Narratives (Best 8)", "8", "Individual Reports"},
                         new object[] {"13", "Quick 1st Year", "All", "Individual Reports"},
                         new object[] {"14", "Disclaimer", "n/a", "Individual Reports"},
                         new object[] {"15", "VitalSigns (Profile)", "1", "Individual Reports"},
                         new object[] {"16", "VitalSigns (Analysis)", "1", "Individual Reports"},
                         new object[] {"17", "VitalSigns (Snapshot)", "1", "Individual Reports"},
                         new object[] {"18", "VitalSigns (Ratings)", "1", "Individual Reports"},
                         new object[] {"18", "Std Package 1", "n/a", "Custom Packages"},
                         new object[] {"19", "Std Package 2", "n/a", "Custom Packages"},
                         new object[] {"20", "Profile Suite", "n/a", "Custom Packages"},
                         new object[] {"21", "Quick Draft", "n/a", "Custom Packages"},
                     };
    
                this.Store2.DataBind();
            }
        }
    </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" ScriptMode="Debug" />
           
           <ext:Store runat="server" ID="EmptyStore" AutoLoad="false">        
           </ext:Store>
    
           <ext:Store runat="server" ID="Store1" AutoLoad="false">
              <Reader>
                 <ext:ArrayReader>
                     <Fields>
                        <ext:RecordField Name="name" />
                        <ext:RecordField Name="value" />
                     </Fields>
                 </ext:ArrayReader>
              </Reader>
            </ext:Store>
            
            <ext:Store runat="server" ID="Store2" AutoLoad="false">
              <Reader>
                 <ext:ArrayReader>
                     <Fields>
                        <ext:RecordField Name="idx" />
                        <ext:RecordField Name="report" />
                        <ext:RecordField Name="num" />
                        <ext:RecordField Name="rtype" />
                     </Fields>
                 </ext:ArrayReader>
              </Reader>
            </ext:Store>
            
            <ext:GridPanel runat="server" ID="GridPanel1" height="300" Width="600" StoreID="EmptyStore" >
            </ext:GridPanel>
            
            <ext:Button ID="Button1" runat="server" Text="Store1">
                 <AjaxEvents>
                    <Click OnEvent="Button1_Click">
                        <ExtraParams>
                            <ext:Parameter Name="Rebind" Value="#{Store1}.getCount() == 0" Mode="Raw" />
                        </ExtraParams>
                    </Click>
                </AjaxEvents> 
            </ext:Button>
            <ext:Button ID="Button2" runat="server" Text="Store2">
                <AjaxEvents>
                    <Click OnEvent="Button2_Click">
                        <ExtraParams>
                            <ext:Parameter Name="Rebind" Value="#{Store2}.getCount() == 0" Mode="Raw" />
                        </ExtraParams>
                    </Click>
                </AjaxEvents> 
            </ext:Button>
        
        </form>
    </body>
    </html>

Similar Threads

  1. [CLOSED] GridPanel.Rows.Changing Background Color of Rows
    By supera in forum 2.x Legacy Premium Help
    Replies: 2
    Last Post: Mar 01, 2012, 5:18 PM
  2. [CLOSED] Trying to dynamically change grid panel columns.
    By GLD in forum 1.x Legacy Premium Help
    Replies: 1
    Last Post: Jun 29, 2011, 8:41 AM
  3. [CLOSED] Rows empty grid using DataTable.
    By stoque in forum 1.x Legacy Premium Help
    Replies: 6
    Last Post: Jun 13, 2011, 9:19 PM
  4. Changing Grid Panel Data Store
    By anand in forum 1.x Help
    Replies: 4
    Last Post: May 14, 2011, 8:07 PM
  5. Load Grid with X amount of empty rows
    By Tbaseflug in forum 1.x Help
    Replies: 0
    Last Post: Sep 19, 2009, 1:06 PM

Posting Permissions