2015-11-20 83 views
0

我有一個Kendo UI Grid,在RoleName屬性上分組。我試圖在分組屬性上設置標題,但似乎無法弄清楚如何做到這一點。Kendo UI網格分組 - 如何設置組標題

視圖模型如下。

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; } 
} 

劍道網格設置如下。

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。關於如何設置組標題的任何想法?

回答

0

添加組字段作爲隱藏的列與ClientGroupHeaderTemplate:

columns.Bound(p => p.RoleName).ClientGroupHeaderTemplate("#=value#").Hidden();