我有一个Kendo Grid,我是从System.Data.DataTable
动态构建的。我在尝试锁定列时遇到问题。
我根据他们的标题设置了一些锁定列,您将在我的代码中看到。布尔检查在预期的位置返回true或false,并在.Locked()
属性中正确设置该值。但网格没有锁定该列,也没有在列菜单中给我Lockable
选项。
请参阅下面的代码:
@model MvcProject.UnitOfWork.ViewModels.Reports.FacilityEquipmentDistributionVm
@(Html.Kendo().Grid<dynamic>()
.Name("resultsGrid")
.Columns(columns =>
{
columns.Group(group => group
.Title("Facility Equipment Distribution Report : Date run - " + DateTime.Now.ToShortDateString())
.Columns(header =>
{
foreach (System.Data.DataColumn column in Model.CombinedTable.Columns)
{
string title = "";
bool showColumn;
if (Model.ColumnTitles.TryGetValue(column.ColumnName, out title))
{
}
else
{
title = column.ColumnName;
}
if (Model.ColumnsToShow.TryGetValue(column.ColumnName, out showColumn))
{
}
else
{
showColumn = false;
}
bool lockColumn = (title == "PropertyRef" || title == "PropertyName" || title == "Address" || title == "Prefix" || title == "Floor");
header.Bound(column.ColumnName)
.Title(title)
.Visible(showColumn)
.Locked(lockColumn)
.Lockable(true)
.Width(title.Length * 8);
}
})
);
})
.HtmlAttributes(new { style = "height: 900px;" })
.Pageable(p => p
.ButtonCount(5)
.PageSizes(true)
.Refresh(true)
)
.Scrollable(s => s.Height("auto").Enabled(true))
.Sortable()
.Reorderable(reorderable => reorderable.Columns(true))
.Filterable()
.Groupable()
.ColumnMenu()
.Resizable(r => r
.Columns(true)
)
.Excel(excel => excel
.FileName("Facility Equipment Distribution.xlsx")
.Filterable(true)
.ProxyURL(Url.Action("_GridExportSave", "Reports"))
.AllPages(true)
)
.DataSource(d => d
.Ajax()
.Read(read => read.Action("_FacilityEquipmentDistributionResults_Read", "Reports").Data("Genesis.Reports.Space.Search.getPaginationData"))
.ServerOperation(true)
.PageSize(20)
)
.ToolBar(tools =>
{
tools.Pdf();
tools.Excel();
})
//PDF removed for now until it is patched
.Pdf(pdf => pdf
.AllPages()
.FileName("FacilityEquipmentDistribution.pdf")
.ProxyURL(Url.Action("_GridExportSave", "Reports"))
)
//.Events(events => events.DataBound("Genesis.Reports.Space.Search.loadTT"))
)
非常感谢任何帮助。
亲切的问候,
加雷
答案 0 :(得分:0)
正如它在kendo文档(锁定列)中所说:
要使用此方法,必须使用at初始化网格 至少有一个锁定列,之后应该有锁定的列 目标列已解锁。
所以我会尝试在开头添加一个锁定的列,然后将其解锁/删除。
var grid = $("#grid").data("kendoGrid");
grid.lockColumn("Lock columns");
grid.unlockColumn("unlock first column");
答案 1 :(得分:0)
“当列分组时,只有根组可以锁定和锁定,遗憾的是,组中的列不支持此类功能。因此,在您的情况下,为了拥有锁定列,您需要删除组并添加列直接到网格。“
由于我们有一个初始分组列作为在我们的网格上拥有标题的“hacky”方式,我们不能这样做,因为我们只能锁定根列,因此我们只能锁定我们的“hacky”列。