jqGrid 中的动态列和使用下拉列表
Dynamic columns and using dropdown list in jqGrid
我有一个关于在 jqGrid 中使用下拉列表的问题。在我的环境中,我使用许可证 jqGrid 4.4.4 - jQuery Grid(版本 4.4.4)和 MVC 5.
在我下面的代码中,我从我的控制器动态创建 ColNames
和 ColModel
。一切正常,除了我想显示下拉列表值的列。现在,下拉列表是空的。为什么是空的?
此外,值应该如何,例如{value:{'FE':'FedEx';'IN':'InTime';'TN':'TNT';'AR':'ARAMEX'}}
,从控制器中的方法动态加载?
model.CreateMeeting = false;
SecondOpinionFacade = new SecondOpinionFacade();
var meeting = SecondOpinionFacade.GetMeeting(id);
model.MeetingDay = meeting.StartDate.Date;
model.MeetingdID = meeting.SecondOpinionMeetingId;
model.FromTime = meeting.StartDate.ToString("HH:mm");
model.ToTime = meeting.EndDate.ToString("HH:mm");
model.NrofGroups = meeting.SecondOpinionGroup.Count;
var list = new[] { new { name = "SecondOpionUserId", index = "SecondOpionUserId", sorttype = "string", sortable=false, hidden = true, editable = true, edittype = "", editoptions= "", formatter = ""} }.ToList();
我在这里尝试将数据放入下拉列表中,但它似乎不起作用,因为下拉列表显示为空。
list.Add(new { name = "Deltagare", index = "Deltagare", sorttype = "string", sortable = true, hidden = false, editable = true, edittype = "select", editoptions = "{value:{'FE':'FedEx';'IN':'InTime';'TN':'TNT';'AR':'ARAMEX'}}", formatter = "select" });
int counter = 1;
meeting.SecondOpinionGroup.OrderBy(x=> x.SecondOpinionGroupId).ForEach(x =>
{
list.Add(new {name = x.SecondOpinionGroupId.ToString(), index = "Grupp" + counter, sorttype = "string", sortable = false, hidden = false, editable = true, edittype = "checkbox", editoptions = "{ value: 'True:False' }", formatter = "checkbox" });
counter++;
});
var list2 = new[] { "SecondOpionUserId" }.ToList();
list2.Add("Deltagare");
for (int i = 1; i <=model.NrofGroups; i++)
{
list2.Add("Grupp"+i);
}
model.ColNames = JsonConvert.SerializeObject(list2);
model.ColModel = JsonConvert.SerializeObject(list);
return View(model);
您使用 string 作为 editoption
的值。这是错的。 editoptions
的值应该是 object。尝试替换
editoptions = "{ value: 'True:False' }"
和
editoptions = "{value:{'FE':'FedEx';'IN':'InTime';'TN':'TNT';'AR':'ARAMEX'}}"
到
editoptions = new { value = "True:False" }
和
editoptions = new { value = "FE:FedEx;IN:InTime;TN:TNT;AR:ARAMEX" }
我有一个关于在 jqGrid 中使用下拉列表的问题。在我的环境中,我使用许可证 jqGrid 4.4.4 - jQuery Grid(版本 4.4.4)和 MVC 5.
在我下面的代码中,我从我的控制器动态创建 ColNames
和 ColModel
。一切正常,除了我想显示下拉列表值的列。现在,下拉列表是空的。为什么是空的?
此外,值应该如何,例如{value:{'FE':'FedEx';'IN':'InTime';'TN':'TNT';'AR':'ARAMEX'}}
,从控制器中的方法动态加载?
model.CreateMeeting = false;
SecondOpinionFacade = new SecondOpinionFacade();
var meeting = SecondOpinionFacade.GetMeeting(id);
model.MeetingDay = meeting.StartDate.Date;
model.MeetingdID = meeting.SecondOpinionMeetingId;
model.FromTime = meeting.StartDate.ToString("HH:mm");
model.ToTime = meeting.EndDate.ToString("HH:mm");
model.NrofGroups = meeting.SecondOpinionGroup.Count;
var list = new[] { new { name = "SecondOpionUserId", index = "SecondOpionUserId", sorttype = "string", sortable=false, hidden = true, editable = true, edittype = "", editoptions= "", formatter = ""} }.ToList();
我在这里尝试将数据放入下拉列表中,但它似乎不起作用,因为下拉列表显示为空。
list.Add(new { name = "Deltagare", index = "Deltagare", sorttype = "string", sortable = true, hidden = false, editable = true, edittype = "select", editoptions = "{value:{'FE':'FedEx';'IN':'InTime';'TN':'TNT';'AR':'ARAMEX'}}", formatter = "select" });
int counter = 1;
meeting.SecondOpinionGroup.OrderBy(x=> x.SecondOpinionGroupId).ForEach(x =>
{
list.Add(new {name = x.SecondOpinionGroupId.ToString(), index = "Grupp" + counter, sorttype = "string", sortable = false, hidden = false, editable = true, edittype = "checkbox", editoptions = "{ value: 'True:False' }", formatter = "checkbox" });
counter++;
});
var list2 = new[] { "SecondOpionUserId" }.ToList();
list2.Add("Deltagare");
for (int i = 1; i <=model.NrofGroups; i++)
{
list2.Add("Grupp"+i);
}
model.ColNames = JsonConvert.SerializeObject(list2);
model.ColModel = JsonConvert.SerializeObject(list);
return View(model);
您使用 string 作为 editoption
的值。这是错的。 editoptions
的值应该是 object。尝试替换
editoptions = "{ value: 'True:False' }"
和
editoptions = "{value:{'FE':'FedEx';'IN':'InTime';'TN':'TNT';'AR':'ARAMEX'}}"
到
editoptions = new { value = "True:False" }
和
editoptions = new { value = "FE:FedEx;IN:InTime;TN:TNT;AR:ARAMEX" }