Jul 10, 2014, 4:49 PM
How to assign store.
Hi,
I am trying to build a grid panel that will have a dynamic schema. The content and schema of the grid will change based on query from user. I am having problems loading the fields from the new query, which I believe is caused by me not updating the store properly. The relevant code I am using is as follows:
//Note: resultTable is of DataTable type
//Inside View
.//A form fields for the query
.
//Button to submit data
I am quite new to .NET framework as well as EXT.Net, hence any tips or advice is appreciated.
Massoud
I am trying to build a grid panel that will have a dynamic schema. The content and schema of the grid will change based on query from user. I am having problems loading the fields from the new query, which I believe is caused by me not updating the store properly. The relevant code I am using is as follows:
//Note: resultTable is of DataTable type
//Inside View
X.Panel()
.ID("CenterNorth")
.Layout(LayoutType.Border)
// .Frame(true)
.Title("Data")
.Items(
X.GridPanel() //Main Content
.ID("GridPanel1")
.Region(Region.Center)
.Frame(true)
.Store(
X.Store()
.Model(Model.resultModel)
.Proxy(X.AjaxProxy()
.Url(@Url.Action("GetFullData"))
.Reader(X.JsonReader().Root("data"))
)
)
. .//A form fields for the query
.
//Button to submit data
X.Button()
.Text("Submit")
.Handler(@"#{DirectMethods}.RunQuery(App.NameSelect.getValue());
App.GridPanel1.getStore().sync()")
//Inside Controller [DirectMethod]
public ActionResult RunQuery(string qry_params)
{
db.SetModelAndData(string.Format("Select * from {0}",qry_params.Trim(new char[]{'"','[',']','\\'})));
this.GetCmp<GridPanel>("GridPanel1").Store.Remove(this.GetCmp<GridPanel>("GridPanel1").GetStore());
Store xStore = new Store();
xStore.DataSource = db.Serialize().ToList(); //Convert to Json format
xStore.Model.Add(db.resultModel);
xStore.DataBind();
this.GetCmp<GridPanel>("GridPanel1").Store.Add(xStore);
this.GetCmp<GridPanel>("GridPanel1").RemoveAllColumns();
for (int i = 0; i < db.resultTable.Columns.Count; i++)
{
this.GetCmp<GridPanel>("GridPanel1")
.AddColumn(
new Column
{
DataIndex = db.resultTable.Columns[i].ColumnName,
Text = db.resultTable.Columns[i].ColumnName
});
}
return this.Direct();
}
public ActionResult GetFullData()
{
return this.Store(db.Serialize().ToList(), db.resultModel);
}
When I run the above code with the submit button, the table columns get updated according to the query, however, the data does not load. I am quite new to .NET framework as well as EXT.Net, hence any tips or advice is appreciated.
Massoud
Last edited by massman07; Jul 10, 2014 at 5:01 PM.