Kendo ui 能否在KendoUI网格中禁用特定单元格或列的选择?
在KendoUI网格中,multi-select看起来相当不错,但它似乎不支持行标题或排除范围 e、 g.我希望不能够选择下面显示的突出显示的单元格(例如,我希望将它们转换为行标题): 最好使用JQuery/Javascript或服务器端C#Razor语法进行回答 更新基于以下答案: 根据lgorrious的建议,我在KendoGrid选项中添加了以下内容:Kendo ui 能否在KendoUI网格中禁用特定单元格或列的选择?,kendo-ui,kendo-grid,Kendo Ui,Kendo Grid,在KendoUI网格中,multi-select看起来相当不错,但它似乎不支持行标题或排除范围 e、 g.我希望不能够选择下面显示的突出显示的单元格(例如,我希望将它们转换为行标题): 最好使用JQuery/Javascript或服务器端C#Razor语法进行回答 更新基于以下答案: 根据lgorrious的建议,我在KendoGrid选项中添加了以下内容: dataBound: function() { $('#grid tr td:first-child').addClass('k
dataBound: function() {
$('#grid tr td:first-child').addClass('k-group-cell');
},
它通过欺骗网格忽略第一列(认为它是分层网格中的分组级别单元)来实现此目的
我不能按原样使用答案,因为我正在为列使用一个数据源,因为它们是动态变化的,但它直接引导我找到了一个简单的解决方案这是一个有点奇怪的解决方案,但我在网格的源代码中发现了这一行:
SELECTION_CELL_SELECTOR = "tbody>tr:not(.k-grouping-row):not(.k-detail-row):not(.k-group-footer) > td:not(.k-group-cell):not(.k-hierarchy-cell)"
不选择具有k类分组小区的td
@(Html.Kendo().Grid<Employee>()
.Name("Grid")
.Columns(columns =>
{
columns.Bound(p => p.Department).HtmlAttributes(new { @class = "k-group-cell" }); //Add class to HtmlAttributes, on the column you don't want to be selected.
columns.Bound(p => p.EmployeeId);
columns.Bound(p => p.Name);
})
.Pageable()
.Sortable()
.Filterable()
.Selectable(x => x.Mode(GridSelectionMode.Multiple).Type(GridSelectionType.Cell))
.DataSource(dataSource => dataSource
.Ajax()
.PageSize(5)
.Read(read => read.Action("GetEmployees", "Home"))
)
)
这样,只需将属性class=“k-group-cell”添加到不希望选择的列中
@(Html.Kendo().Grid<Employee>()
.Name("Grid")
.Columns(columns =>
{
columns.Bound(p => p.Department).HtmlAttributes(new { @class = "k-group-cell" }); //Add class to HtmlAttributes, on the column you don't want to be selected.
columns.Bound(p => p.EmployeeId);
columns.Bound(p => p.Name);
})
.Pageable()
.Sortable()
.Filterable()
.Selectable(x => x.Mode(GridSelectionMode.Multiple).Type(GridSelectionType.Cell))
.DataSource(dataSource => dataSource
.Ajax()
.PageSize(5)
.Read(read => read.Action("GetEmployees", "Home"))
)
)
@(Html.Kendo().Grid())
.名称(“网格”)
.列(列=>
{
columns.Bound(p=>p.Department).HtmlAttributes(new{@class=“k-group-cell”});//在不希望被选中的列上向HtmlAttributes添加类。
columns.Bound(p=>p.EmployeeId);
columns.Bound(p=>p.Name);
})
.Pageable()
.Sortable()
.可过滤()
.Selectable(x=>x.Mode(GridSelectionMode.Multiple).Type(GridSelectionType.Cell))
.DataSource(DataSource=>DataSource
.Ajax()
.页面大小(5)
.Read(Read=>Read.Action(“GetEmployees”、“Home”))
)
)
还有一个java脚本示例:
<div id="grid" style="width: 400px;"></div>
<script type="text/javascript">
$(document).ready(function () {
var grid = $("#grid").kendoGrid({
columns: [
{
field: "Department",
title: "Department",
attributes: {
"class": "k-group-cell" //Same idea with the class attribute
}
}, {
field: "Name",
title: "Full Name"
}, {
field: "EmployeeId",
title: "Employee ID"
}
],
dataSource: {
data: [
{
EmployeeId: 0,
Name: "Joe Mintot",
Department: "Finance"
}, {
EmployeeId: 1,
Name: "Jane Smith",
Department: "IT"
}
],
schema: {
model: {
id: "EmployeeId",
fields: {
EmployeeId: { type: "number" },
Name: { type: "string" },
Department: { type: "string" }
}
}
},
pageSize: 10
},
selectable: "multiple cell",
scrollable: {
virtual: true
},
pageable: true
}).data("kendoGrid");
});
</script>
$(文档).ready(函数(){
var grid=$(“#grid”).kendoGrid({
栏目:[
{
字段:“部门”,
标题:“部门”,
属性:{
“class”:“k-group-cell”//与class属性相同
}
}, {
字段:“名称”,
标题:“全名”
}, {
字段:“EmployeeId”,
标题:“员工ID”
}
],
数据源:{
数据:[
{
员工ID:0,
姓名:“乔·明特”,
部门:“财务”
}, {
雇员编号:1,
姓名:“简·史密斯”,
部门:“IT”
}
],
模式:{
型号:{
id:“雇员id”,
字段:{
EmployeeId:{type:“number”},
名称:{type:“string”},
部门:{type:“string”}
}
}
},
页面大小:10
},
可选:“多单元”,
可滚动:{
虚拟的:真的
},
可分页:正确
}).数据(“kendoGrid”);
});
问题,当你说我不想选择突出显示的单元格时,你是指单元格还是行?@OnaBai:我使用的是多单元格选择(非行)+1+25+50。。。这门课的技巧让我直接找到了答案(问题更新)。非常感谢!