The multi-select seems pretty good in KendoUI Grid, but it doesn't appear to support row headers or excluding ranges.
e.g. I want to not be able to select the highlighted cells shown below (e.g. I want to turn them into row headers):
Answer in JQuery/Javascript or server-side C# Razor syntax preferred.
Based on lgorrious' suggestion below, I added this to the KendoGrid options:
dataBound: function() {
$('#grid tr td:first-child').addClass('k-group-cell');
},
which does the trick by fooling the grid into ignoring the first column (thinking it is a grouping level cell in a hierarchical grid).
I could not use the answer as-is as I am using a dataSource for the columns as they vary dynamically, but it lead me straight to a simple solution
This is a bit of a quirky work around, but I found this line in the grid's source code:
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)"
td with class k-group-cell will not be selected.
With that, just add the attribute class = "k-group-cell" to the column that you don't want to be selected.
@(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"))
)
)
One more java script example:
<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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With