我只需要在kendo网格中禁用仅一列的大小调整。 我看过columnresize事件,但我不明白如何在下面的网格示例中使用它。
我注意到有类似的question
我的网格 -
@(Html.Kendo().Grid<CCCAdmin.ViewModels.AdminReportViewModel>().Name("AdminReportGrid")
.HtmlAttributes(new {@class = "table table-bordered"})
.Columns(columns =>
{
columns.Bound(l => l.Id).Width("11%").Title("Id");
columns.Bound(l => l.CustomerName).Width("30%");
}).Resizable(r => r.Columns(true))
.Excel(excel => excel
.FileName("Admin Report Export.xlsx")
.Filterable(true)
.ProxyURL(Url.Action("Excel_Export_Save", "AdminReport")))
.DataSource(dataSource => dataSource
.Ajax().Read(read => read.Action("AdminReport_Read", "AdminReport"))
.Destroy(update => update.Action("AdminReportDestroy", "AdminReport"))
.Sort(sort => sort.Add("CallCounting").Descending())
.PageSize(20)
.Model(model =>
{
model.Id(a => a.Id);
})
)
.Events(events =>
{
events.DataBound("dataBound");
events.ExcelExport("onExcelExport");
}
)
.ClientDetailTemplateId("CustomerInvoices")
.Sortable()
.Filterable()
)
答案 0 :(得分:0)
Kendo ASP.NET MVC中没有开箱即用的功能,但您可以使用Javascript完成任务。在以下示例中,不会调整列Id
的大小。
var grid = $("#GridName").data("kendoGrid");
grid.resizable.bind("start", function (e) {
if ($(e.currentTarget).data("th").data("field") == "Id") {
e.preventDefault();
setTimeout(function () {
grid.wrapper.removeClass("k-grid-column-resizing");
$(document.body).add(".k-grid th").css("cursor", "");
});
}
});
<强>演示强>
$(function(){
$("#grid").kendoGrid({
dataSource: {
data: [
{Id: "1", FirstName: "Amar",LastName: "X"},
{Id: "2", FirstName: "Akbar",LastName: "Y"},
{Id: "3", FirstName: "Anthony",LastName: "Z"}
]
},
resizable: true
});
var grid = $("#grid").data("kendoGrid");
grid.resizable.bind("start", function(e) {
if ($(e.currentTarget).data("th").data("field") == "Id") {
e.preventDefault();
setTimeout(function(){
grid.wrapper.removeClass("k-grid-column-resizing");
$(document.body).add(".k-grid th").css("cursor", "");
});
}
});
});
&#13;
<head>
<title>Kendo UI Snippet</title>
<link rel="stylesheet" href="https://kendo.cdn.telerik.com/2018.2.516/styles/kendo.common.min.css"/>
<link rel="stylesheet" href="https://kendo.cdn.telerik.com/2018.2.516/styles/kendo.rtl.min.css"/>
<link rel="stylesheet" href="https://kendo.cdn.telerik.com/2018.2.516/styles/kendo.silver.min.css"/>
<link rel="stylesheet" href="https://kendo.cdn.telerik.com/2018.2.516/styles/kendo.mobile.all.min.css"/>
<script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
<script src="https://kendo.cdn.telerik.com/2018.2.516/js/kendo.all.min.js"></script>
</head>
<body>
<p>The <strong>Id</strong> column cannot be resized:</p>
<div id="grid"></div>
</body>
&#13;