如何在页面加载时将剑道网格高度设置为固定值

How to Set Kendo grid height to a fixed value on page load

本文关键字:设置 高度 网格 加载      更新时间:2023-09-26

我正在尝试获得一个具有静态高度和宽度的剑道网格。当我分页时,它绝对不能改变高度和宽度(由于数据大小不同,它现在这样做)。如果数据增加,我应该提供滚动。

问题是,当页面第一次加载数据时,剑道网格没有设置为固定的高度和宽度。但是如果我调整窗口的大小,它就会得到固定的高度,并在剑道网格中提供滚动选项

所以我可以在剑道网格第一次加载时将其高度设置为固定值

剑道版本:v2014.1.318

代码:

$("#ViewUnitContainerTracking").kendoGrid({
                        sortable: true,
                        height:"280px",
                        columns: [
                            {
                                field: "UnitCode",
                                title: "Unit",
                                width: "15%"
                            },
                             {
                                 field: "UnitName",
                                 title: "Unit Name",
                                 width: "35%"
                             },
                            {
                                field: "Status",
                                title: "St",
                                width: "5%",
                                template: $("#TemplateViewUnitTrackingStatus").text()
                            },
                             {
                                 field: "StartDate",
                                 title: "Start Date",
                                 //template: $("#TemplateViewUnitTrackingStartDate").text(),
                                 width: "15%",
                                 //type: "date"
                             },
                              {
                                  field: "EndDate",
                                  title: "End Date",
                                  //template: $("#TemplateViewUnitTrackingEndDate").text(),
                                  width: "15%",
                                  //type: "date"
                              },
                             {
                                 field: "AssessPrgress",
                                 title: "%OAP",
                                 width: "10%"
                             },
                             {
                                 field: "Status",
                                 title: "Status",
                                 hidden: true
                             }
                        ],
                        editable: false,
                        resizable: false,
                        mobile: true,
                        dataSource: data.UnitList
                    });

Html页面:

<div id="ViewUnitContainerTracking" style="padding-top:10px;">
</div>

问题的答案是:-

dataBound: function() {
    $('#ViewUnitContainerTracking .k-grid-content').height(280);
}

将此添加到剑道网格将解决问题。在数据绑定事件之后,我们可以设置网格的自定义Css属性,因为网格动态高度是在该事件之前设置的。

我动态地这样做,将网格设置为100%,意味着减去引导程序页眉和页脚:

<script type="text/javascript">
    var gridElement = $("#serviceGrid");    
    function resizeGrid() {
        $("#serviceGrid").css("height", $(window).height() - $("#itheader").height() - $("#itfooter").height() - 2);
        gridElement.data("kendoGrid").resize();
    }    
    $(window).resize(function() {
        resizeGrid();
    });
</script>

"-2"是因为顶部和底部有两个1px边界。。

我发现这个更可靠的选项也适用于锁定/冻结列。您可以在窗口的调整大小事件处理程序中调用以下代码行

var availableHeight = 500; // Calculate this value based on space available in grid's parent container 
$('#YOUR_GRID_ID').data('kendoGrid').setOptions({ height:  availableHeight})