我需要在特定列上默认对网格进行分组,并且不允许用户删除该列上的分组。这可能吗?
答案 0 :(得分:20)
您可以在创建网格时设置初始分组。您可以通过将groupable属性设置为false或者不将其包含在配置中来阻止用户删除或更改分组。
以下两个示例都根据FirstName对网格进行分组。
Razor HTML示例:
@(Html.Kendo().Grid(Model.Person)
.Name("grid")
.Columns(columns =>
{
columns.Bound(model => model.FirstName);
columns.Bound(item => item.LastName);
})
.Groupable(g => g.Enabled(false))
.DataSource(dataSource => dataSource
.Server()
.Group(groups => groups.Add(p => p.FirstName))
)
JavaScript示例:
$("#grid").kendoGrid({
dataSource: {
data: [{FirstName: "FirstName1", LastName: "LastName1"},
{FirstName: "FirstName1", LastName: "LastName2"},
{FirstName: "FirstName3", LastName: "LastName3"},
{FirstName: "FirstName1", LastName: "LastName4"}],
group: { field: "FirstName" } // set grouping for the dataSource
},
groupable: false, // this will remove the group bar
sortable: true,
columns: ["FirstName","LastName"]
});
Link to a fiddle for the JavaScript example.
Source JavaScript示例