0

我需要将列名或值“无”传递给我的剑道网格,以便根据 Viewbag 元素的值有条件地对其进行分组。当我按预期传递它的组中的列名时。我的问题是如果传入值“无”,则不进行分组。我拥有的代码是:

@(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"

4

1 回答 1

6

只需在Group选项中添加条件:

.Group(grp => {
    if(ViewBag.groupBy != "none") {
        grp.Add(ViewBag.groupBy, typeof(string));
    }
})
于 2013-04-25T15:42:29.540 回答