1

我有两个问题。我在剑道窗口中包含的页面上有一个网格。我需要增加/减少网格行的大小以确保它填充窗口的整个高度。我在另一个页面上也有一个网格,它位于一个需要调整大小以适应文档窗口调整大小时其容器的高度的 Div 内。

我有剑道支持给我的以下代码,但它没有做我需要它做的事情。它仅将网格设置为其容器的 100%。但这会在行下方留下空白。我希望没有空白,并且让行动态更改它们的高度,以便它们都适合其中一个的空间,并在计算有多少行适合另一个窗口的大小后动态更改 pageSize .

其中一个网格是前十名网格,另一个是所有员工网格的列表。

    $(window).resize(function() {
        var gridElement = $("#grid"),
            newHeight = gridElement.innerHeight(),
            otherElements = gridElement.children().not(".k-grid-content"),
            otherElementsHeight = 0;

        otherElements.each(function(){
            otherElementsHeight += $(this).outerHeight();
        });

        gridElement.children(".k-grid-content").height(newHeight - otherElementsHeight);
    });

为文字的数量道歉,但我已经坚持了好几天,想给你尽可能多的信息。

编辑:水平调整大小按预期开箱即用。为什么身高不一样?:S

EDIT2:这是我用于我的网格的代码,它位于剑道窗口的内容部分

@(Html.Kendo().Grid<DataModels.UI.OperatorPickRatesChartModel>()
                    .Name("topTenPickersChart")
                    .Columns(columns =>
                    {
                        columns.Bound(b => b.operatorId).Title("Operator Id"); 
                        columns.Bound(b => b.averagePicksLastThirty).Title(" Average Picks Last Thirty");
                    })
                    .DataSource(dataSource => dataSource
                        .Ajax()
                        .Model(model => 
                            {
                                model.Field(b => b.operatorId).Editable(false);
                                model.Field(b => b.averagePicksLastThirty).Editable(false);
                            })
                            .Read("operatorTopTenPickRates", "DashBoard")           
                        .Events(events => events.Error("error"))
                        .PageSize(10)                           
                    )
                    .Filterable()

)

4

1 回答 1

2

对于以下解决方案,您需要将表格放在使用 100% 区域(宽度和高度)的 HTML 元素中。为了得到它,我所做的是将 HTML 定义为:

<div id="container">
    <div id="grid"></div>
</div>

和以下 CSS 样式:

#container {
    position: absolute;
    top: 0;
    bottom: 0;
    left: 0;
    right: 0;
}

不,一旦调整窗口大小,我们需要做一些数学运算......

$(window).resize(function () {
    // Get container height
    var containerH = $("#container").height();
    // Get Grid height
    var tableH = grid.element.height();
    // Get Grid body height (the remaining is header and footer)
    var bodyH = grid.table.height();
    // The new height of the body is:
    grid.table.height(containerH - tableH + bodyH - 1);
});

JSFiddle 在这里展示:http: //jsfiddle.net/OnaBai/dB5CF/

编辑:如果您的网格在剑道窗口内,那么您必须:

  1. 您不需要 CSS 定义。
  2. 您不是在调整大小$(window),而是在调整 kendoWindow,所以我将把该代码放在 Kendo Windowresize事件处理程序中。
  3. 您需要为 Kendo Window 设置初始宽度。

所以你的代码应该是这样的:

$("#container").kendoWindow({
    width : 400,
    resize: function (e) {
        console.log("resize", e);
        var containerH = $("#container").height();
        var tableH = grid.element.height();
        var bodyH = grid.table.height();
        grid.table.height(containerH - tableH + bodyH - 1);
    }
});

var grid = $("#grid").kendoGrid({
    dataSource: {
        data    : createRandomData(100),
        pageSize: 10,
        schema  : {
            model: {
                fields: {
                    Id       : { type: 'number' },
                    FirstName: { type: 'string' },
                    LastName : { type: 'string' },
                    City     : { type: 'string' }
                }
            }
        }
    },
    editable  : false,
    pageable  : true,
    columns   : [
        { field: "FirstName", width: 90, title: "First Name" },
        { field: "LastName", width: 90, title: "Last Name" },
        { field: "City", width: 100 }
    ]
}).data("kendoGrid");

修改后的 JS Fiddle 在这里:http: //jsfiddle.net/OnaBai/dB5CF/2/

于 2013-08-20T17:26:48.533 回答