我正在尝试完成某些事情,但我不确定这是否完全有可能。
我有一个使用 ASP.NET MVC 的 Telerik MVC 网格。
网格的默认分页大小为 10,但是我希望能够根据用户分辨率的大小调整页面大小(行数)。这可能吗?
谢谢,
保罗
我正在尝试完成某些事情,但我不确定这是否完全有可能。
我有一个使用 ASP.NET MVC 的 Telerik MVC 网格。
网格的默认分页大小为 10,但是我希望能够根据用户分辨率的大小调整页面大小(行数)。这可能吗?
谢谢,
保罗
这绝对是可能的。
我创建了一个解决方案来完成同样的事情 - 但是你必须修改它才能自己获得适当的网格高度(不包括任何菜单/页眉/页脚等)
这些步骤应该可以帮助您:
首先 - 您需要向 MVC Grid 添加一个“onLoad”事件:
.ClientEvents(events =>events.OnLoad("onLoad"))
下一步 - 创建一个 Javascript 事件来处理 $(document).ready() 中的“onLoad”:
function onLoad(e)
{
//Bread and Butter will go here.
}
最后 - 最后一步是计算网格未占用的空间(Firebug 可能会有所帮助)并对其进行修改,直到您的“公式”在大多数浏览器中都有效:
function onLoad(e)
{
//Gets the height of the Window. ($(window).height())
//Subracts the height of any menus/headers/footers (in this case 275)
//Then divide by our "magic number" which you will need to tinker with
//to determine how the grid looks in different browsers. (in this case 28)
var height = Math.floor(($(window).height()-275)/28);
var grid = $("#YourGrid").data("tGrid");
grid.pageSize = height;
}
公式 :
$(window).height() - [Occupied Space] / [Magic Number]
[Occupied Space] - Total CSS Height of all objects above the Grid.
[Magic Number] - You will have to play with this one and try it out on
different browsers until you get the expected results.
这应该会根据您的窗口高度自动调整您的行数。唯一棘手的部分是使用占用的空间量找出您自己的“公式”,然后选择一个幻数除以。
希望这可以帮助!