Kendo UI Grid分组 - 如何设置组标题

时间:2015-11-20 15:23:25

标签: asp.net-mvc kendo-ui kendo-asp.net-mvc

我有一个Kendo UI Grid,在RoleName属性上进行分组。我试图在分组属性上设置标题,似乎无法弄清楚如何做到这一点。

视图模型如下。

public class UserMembershipViewModel
{
    [Display(Name = "Username")]
    [UIHint("UsersDropdown")]
    public string UserId { get; set; }

    [Display(Name = "Group")]
    [UIHint("RolesDropdown")]
    public string RoleId { get; set; }

    [Display(Name = "Group")]
    public string RoleName { get; set; }

    [HiddenInput(DisplayValue = false)]
    [Display(Name = "Username")]
    public string UserName { get; set; }

    [HiddenInput(DisplayValue = false)]
    [Display(Name = "Email")]
    public string Email { get; set; }
}

Kendo Grid的设置如下。

Html.Kendo().Grid(Model)
    .Name("Grid")
    .Columns(columns =>
    {
        columns.Bound(p => p.UserName);
        columns.Bound(p => p.Email);
        columns.Command(command =>
        {
            command.Destroy();
        }).Title("Actions").Width(200);
    })
    .Editable(editable => editable
                .Mode(GridEditMode.PopUp)
                .Window(window => window
                    .Title("Add Group Member")
                    .Draggable(true)))
    .ToolBar(toolbar => toolbar.Create().Text("Add Group Member"))
    .Pageable()
    .Sortable()
    .Groupable()
    .DataSource(dataSource => dataSource
            .Ajax()
            .Model(model =>
            {
                model.Id(user => user.UserId);
                model.Field(user => user.UserId).Editable(false);
            })
            .Events(events => events
                .Sync("sync_handler"))
            .Group(group => group.Add(model => model.RoleName))
            .Create(create => create.Action("MembershipCreate", "UserManagement"))
            .Read(read => read.Action("MembershipRead", "UserManagement"))
            .Destroy(destroy => destroy.Action("MembershipDestroy", "UserManagement"))
    )

结果就是这个..

Kendo UI Grid

视图模型中的RoleName属性具有Display属性。此属性适用于在列标题上设置标题(您可以在图像中看到Username列标题),但不适用于组标题。

因此图片中的RoleName应为Group。关于如何设置组标题的任何想法?

1 个答案:

答案 0 :(得分:2)

使用ClientGroupHeaderTemplate:

将组字段添加为隐藏列
columns.Bound(p => p.RoleName).ClientGroupHeaderTemplate("#=value#").Hidden();