Feb 10, 2009, 7:44 PM
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:
code behind:
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);
}