我需要将列名或值'none'传递给我的kendo网格,以根据Viewbag元素的值有条件地对其进行分组。当我按预期传递组中的列名称时。我的问题是如果传入值'none'则不进行分组。我所拥有的代码是:
@(Html.Kendo().Grid<dynamic>()
.Name("exportGrid")
.DataSource(dataSource =>
{
dataSource.Ajax()
.Read("ReadGrid", "Report", new { id = Model.Inquiry_ID })
.Group(grp => grp.Add(ViewBag.groupBy, typeof(string)))
.Model(m =>
{
// Add the fields to the dynamic model
foreach (var field in Fields)
{
switch (field.DATA_TYP_NUM)
{
case 1: m.Field(field.INTERNL_NME, typeof(string)); break;
case 2: m.Field(field.INTERNL_NME, typeof(double?)); break;
case 3: m.Field(field.INTERNL_NME, typeof(double?)); break;
case 4: m.Field(field.INTERNL_NME, typeof(DateTime?)); break;
}
}
})
.ServerOperation(true);
})
.Groupable()
.Filterable()
.Sortable()
.ColumnMenu()
.Events(e => e.DataBound("onDataBound"))
.Resizable(resize => resize.Columns(true))
.Columns(columns =>
正如我所说 - 这很好但我需要一种在.Group(....)
Viewbag.groupBy == "none"
子句的方法
答案 0 :(得分:6)
只需在Group
选项中添加条件:
.Group(grp => {
if(ViewBag.groupBy != "none") {
grp.Add(ViewBag.groupBy, typeof(string));
}
})