动态更改容器上Kendo网格行的高度Kendo窗口的大小
Dynamically change height of rows of Kendo Grid on container Kendo window resize
我有两个问题。我在一个包含在剑道窗口中的页面上有一个网格。我需要增加/减少网格行的大小,以确保它填充整个窗口的高度。我在另一个页面上也有一个网格,它就在Div中,需要调整大小以适应文档窗口上容器的高度。
Kendo支持给了我以下代码,但它并没有完成我需要它做的事情。它只将网格设置为其容器的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
编辑2:这是我在网格中使用的代码,它位于剑道窗口的内容部分中
@(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()
)
对于以下解决方案,您需要将表放在使用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/
编辑:如果你的网格在剑道窗口内,那么你必须:
- 您不需要CSS定义
- 您不是在调整
$(window)
的大小,而是在调整kendoWindow的大小,所以我将把代码放在KendoWindowresize
事件处理程序中 - 你需要为剑道窗口设置一个初始宽度
所以你的代码应该是这样的:
$("#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/
相关文章:
- electronic BrowserWindow的最小高度和宽度在hide()show()方法之后不起作用
- ExtJS——在展开/折叠时调整面板高度
- 分析高度属性时出现意外值{{specs.height}}.index.html
- Kendo:我该如何在树视图中创建一个递归的hieiarchy
- 单击页面上的链接后高度发生变化
- 不加载宽度和高度的角度pintura
- 查找元素高度,包括边距
- 如何自动调整标签的高度以适应内容
- Javascript高度问题
- 使用JavaScript根据窗口/视口的高度动态调整图像大小
- 如何计算每个元素's的高度,并将这些值用作函数中的变量
- 如果宽度是百分比,如何设置以px为单位的图像高度
- 使用导航属性创建Kendo UI网格模型的问题
- 通过jquery设置最小高度
- 文档就绪提供了错误的选择器高度
- 调整缩放窗口高度提升缩放
- 根据图像高度添加类
- 检测非移动页面上的移动设备屏幕宽度和高度
- 更改代码镜像中TextArea的高度和宽度
- 动态更改容器上Kendo网格行的高度Kendo窗口的大小