【问题标题】:Kendo MVC Grid Columns not lockingKendo MVC 网格列未锁定
【发布时间】:2015-10-07 13:03:29
【问题描述】:

我有一个剑道网格,我正在从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"))

)

任何帮助将不胜感激。

亲切的问候,

加雷斯

【问题讨论】:

  • 我遇到了类似的事情,当使用Grid&lt;dynamic&gt;() 时,.Columns(columns =&gt; 下的代码似乎对 gird 没有影响。详细问题在这里stackoverflow.com/questions/37437363/…。谢谢队友

标签: c# asp.net-mvc kendo-ui kendo-grid kendo-asp.net-mvc


【解决方案1】:

正如剑道文档中所说的(锁定列):

为了使用这个方法,网格必须初始化为 at 至少一个被锁定的列,并且之后应该有被锁定的列 目标列已解锁。

所以我会尝试在开始时添加一个锁定的列,然后将其解锁/删除。

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

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

【讨论】:

  • 原来如此,前四列被锁定,或者至少应该被锁定。
【解决方案2】:

Telerik 的Radoslav 回复我说:

“当列被分组时,只有根组可以锁定和锁定,不幸的是,组中的列不支持这种功能。所以在你的情况下,为了有锁定的列,你需要删除组并添加列直接到电网。”

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

【讨论】:

    猜你喜欢
    • 2018-09-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-25
    • 1970-01-01
    相关资源
    最近更新 更多