【问题标题】:How to set column width to autofit in Kendo Grid MVC如何在 Kendo Grid MVC 中设置列​​宽以自动调整
【发布时间】:2015-04-16 15:24:00
【问题描述】:

我使用具有多列的剑道网格页面。
我想将列宽设置为自动调整并自动更改宽度。
请帮帮我,谢谢

@(Html.Kendo().Grid<GardeshKar.Models.v_marhaleh_marahel>()
    .Name("grdMarahel_Gardeshkar")
    .ToolBar(toolbar => toolbar.Custom().Name("btnAddMarhaleh").Text("اضافه").HtmlAttributes(new { id = "btnAddMarhaleh", href = "#" }))
    .Columns(columns =>
    {
        columns.Bound(c => c.Code).Width(50).Title("کد");
        columns.Bound(c => c.Desc).Width(150).Title("شرح");//Autofit
        columns.Command(c => c.Destroy().Text("حذف")).Width(70).Title("عملیات");
    })
    .HtmlAttributes(new { style = "height: 380px;" })
    .Scrollable()
    .Sortable()
    .Resizable(rl => rl.Columns(true))
    .Selectable(sl => sl.Mode(GridSelectionMode.Single).Type(GridSelectionType.Row))
    .DataSource(dataSource => dataSource
        .Ajax()
        .Model(m => m.Id(p => p.id))
        .Read(read => read.Action("Get_DS_Marahel_Gardeshkar", "Home",
                    new { intGardesh = ViewBag.CodeGardeshKar }))
        .Destroy(del => del.Action("Del_Marhaleh_GardeshKar", "Home")))
)  

具有自动调整功能的特定列必须将列宽更改为自动调整

【问题讨论】:

  • 您是否尝试过从列中删除宽度分配?
  • 确保声明 Grid 的元素不受任何样式的宽度限制。
  • 此网格或列不使用样式
  • 移除可滚动的,然后它将设置为自动调整。 Kendo Grid 不允许自动设置可滚动的宽度。

标签: c# model-view-controller kendo-ui kendo-grid


【解决方案1】:

一种方法是删除“Scrollable”属性,或者您可以在 dataBound 事件中使用此功能。

        function Autocolumnwidth(e) {
            var grid = e.sender;
            for (var i = 0; i < grid.columns.length; i++) {
                 grid.autoFitColumn(i);
            }
        }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-04-05
    • 2012-11-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多