Mik*_*keD 0 asp.net-mvc viewbag kendo-ui kendo-grid
我需要将列名或值'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 =>
Run Code Online (Sandbox Code Playgroud)
正如我所说 - 这工作正常,但我需要一种方法来排除.Group(....)条款Viewbag.groupBy == "none"
只需在Group选项中添加条件:
.Group(grp => {
if(ViewBag.groupBy != "none") {
grp.Add(ViewBag.groupBy, typeof(string));
}
})
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3345 次 |
| 最近记录: |