jQuery jqGrid:如何更改 jqGrid 的宽度?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11859304/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
jqGrid: How can I change the width of the jqGrid?
提问by user603007
I would like to change the width of a jqGrid. I tried to set the width in my griddefinition:
我想更改 jqGrid 的宽度。我试图在我的 griddefinition 中设置宽度:
width: '800px'
Is there another way?
还有其他方法吗?
回答by Rohan Büchner
You could use the setGridWidth
property
您可以使用该setGridWidth
属性
$('#gridId').jqGrid('setGridWidth', '800');
If you want the grid to re-size dynamically, hook into the window re-size function, but remember to set the initial width
如果希望网格动态调整大小,钩入窗口调整大小功能,但记得设置初始宽度
var DataGrid = $('#gridId');
//sets the grid size initially
DataGrid.jqGrid('setGridWidth', parseInt($(window).width()) - 20);
//handles the grid resize on window resize
$(window).resize(function () {
DataGrid.jqGrid('setGridWidth', parseInt($(window).width()) - 20);
});