Jul 18, 2014, 2:28 AM
[CLOSED] Dynamic store fields being added more than once (MVC Razor)
I am building a grid dynamically in the controller and placing it in a panel as the container with a direct event. When the store is being loaded on the client side I get the following error:
Unhandled exception at line 131, column 3953 in eval code
0x800a138f - JavaScript runtime error: Unable to get property 'addField' of undefined or null reference
a portion of the Call Stack follows:
If I continue to run through the error, my data shows correctly, but every time I access that grid I get the error.
Here is the code for the Panel:
Jake
Unhandled exception at line 131, column 3953 in eval code
0x800a138f - JavaScript runtime error: Unable to get property 'addField' of undefined or null reference
a portion of the Call Stack follows:
Ext.getCmp("2container").add({store:{model:Ext.define(Ext.id(), {extend: "Ext.data.Model", fields:[{name:"Id",type:"int"},{name:"plusHolder",type:"string"},{name:"04/30/2014",type:"float"}
...
viewConfig:{xtype:"gridview"}});App.id41d1507a39dc6ac4.addField({"name":"04/30/2014","type":"float"},2,true);
I hope that you can see that the last bit there is a second attempt to load the same field.If I continue to run through the error, my data shows correctly, but every time I access that grid I get the error.
Here is the code for the Panel:
X.Panel()
.Title("Allocations")
.ID(ViewBag.clientId + "container")
.Items(
X.Button()
.Text("Add Grid")
.Icon(Icon.Add)
.DirectEvents(de =>
{
de.Click.Url = Url.Action("CreateAllocationGrid");
de.Click.ExtraParams.Add(new { id = ViewBag.clientId, containerId = ViewBag.clientId + "container" });
de.Click.EventMask.ShowMask = true;
de.Click.EventMask.Target = MaskTarget.CustomTarget;
de.Click.EventMask.CustomTarget = ViewBag.ClientId + "container";
de.Click.Before = "this.hide()";
})
and the code for the Controller public ActionResult CreateAllocationGrid(string id, string containerId)
{
int clientId = Convert.ToInt32(id);
Client client = ClientRepository.GetClientDetails(db, clientId);
List<DateTime> dateTimeList = new List<DateTime>();
foreach (DateTime clientValueDate in client.ClientValues.Keys.OrderByDescending(d => d.Date).Distinct())
{
string dateString = clientValueDate.ToString("d");
dateTimeList.Add(clientValueDate);
}
this.BuildGrid1(dateTimeList, client.Id).AddTo(containerId);
return this.Direct();
}
private Ext.Net.GridPanel BuildGrid1(List<DateTime> dateTimeList, int clientId)
{
Client client = ClientRepository.GetClientDetails(db, clientId);
Ext.Net.GridPanel grid = new Ext.Net.GridPanel
{
Border = false,
Store =
{
new Store
{
Proxy =
{
new AjaxProxy
{
Url = Url.Action("AllocationStore"),
Reader = { new JsonReader() { Root = "data" } }
}
},
Parameters =
{
new StoreParameter
{
Name = "id",
Value = clientId.ToString(),
Mode = ParameterMode.Raw
}
},
Model =
{
new Model
{
IDProperty = "Id",
Fields =
{
new ModelField("Id", ModelFieldType.Int),//0 Client ID
}
}
}
}
},
ColumnModel =
{
Columns =
{
new Column { Hidden = true, DataIndex = "Id", Locked = true } //0 Client ID
}
},
View =
{
new Ext.Net.GridView()
{
StripeRows = true,
TrackOver = true
}
}
};
Store store = grid.GetStore();
int fieldCount = 2;
foreach (DateTime dt in dateTimeList)
{
string dateString = dt.Date.ToString("d");
ModelField field = new ModelField(dateString, ModelFieldType.Float);//this is the value field for the date
store.AddField(field, fieldCount);//the field "date" and order that it appears in the store for the heading
fieldCount++;
ModelField offOnField = new ModelField(dateString + "OffOn", ModelFieldType.Boolean);
store.AddField(offOnField, fieldCount);
fieldCount++;
Column col = new Column
{
Renderer = { Fn = "checkFlag" }
};
col.Text = dateString;
col.DataIndex = dateString;
col.Renderer.Format = RendererFormat.UsMoney;
grid.ColumnModel.Columns.Add(col);
}
return grid;
}
public ActionResult AllocationStore(string id)
{
int clientId = Convert.ToInt32(id);
Client client = ClientRepository.GetClientDetails(db, clientId);
List<DateTime> dateTimeList = new List<DateTime>();
List<object> clientStuff = new List<object>();
var _tempObject = new ExpandoObject() as IDictionary<string, Object>;
_tempObject.Add("Id", client.Id);
string expand = "Expand";
_tempObject.Add("plusHolder", expand);
foreach (DateTime clientValueDate in client.ClientValues.Keys.OrderByDescending(d => d.Date).Distinct())
{
string dateString = clientValueDate.ToString("d");
dateTimeList.Add(clientValueDate);
_tempObject.Add(dateString, client.ClientValues[clientValueDate]);
if (client.ClientRecommendationOffOnDateClient.ContainsKey(clientValueDate))
{
_tempObject.Add(dateString + "OffOn", client.ClientRecommendationOffOnDateClient[clientValueDate]);
}
else
{
_tempObject.Add(dateString + "OffOn", true);
}
}
clientStuff.Add(_tempObject);
return this.Store(clientStuff);
}
Any help would be greatly appreciated.Jake
Last edited by Daniil; Jul 19, 2014 at 6:19 AM.
Reason: [CLOSED]