Kendo MVC 网格列未锁定

Kendo MVC Grid Columns not locking

我有一个从 System.Data.DataTable 动态构建的 Kendo 网格。我在尝试锁定列时遇到问题。

正如您将在我的代码中看到的那样,我根据标题将一些列设置为锁定。布尔检查在预期的地方返回为 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"))

)

如有任何帮助,我们将不胜感激。

亲切的问候,

加雷思

如 kendo 文档(锁定列)中所述:

In order to use this method, the grid must be initialized with at least one locked column, and there should be locked columns left after the target column is unlocked.

所以我会尝试在开头添加一个锁定的列,然后将其添加 unlocked/removed。

    var grid = $("#grid").data("kendoGrid");
    grid.lockColumn("Lock columns");
    grid.unlockColumn("unlock first column");

http://jsfiddle.net/calinaadi/p2710yoL/

Telerik 的 Radoslav 回信说:

"When the columns are grouped only the root groups can be lockable and locked, unfortunately the columns into the group does not support such functionality. So in your case in order to have locked columns you need to remove the group and add columns directly to the grid. "

因为我们有一个初始分组列作为 "hacky" 在我们的网格上有标题的方式,我们不能这样做,因为我们只能锁定根列,因此我们只能锁定我们的 "hacky" 专栏。