Ste*_*hry 69
在生产中使用它已经有一段时间没有任何抱怨(可以在你的网站上进行一些调整以查看...例如,减去侧边栏的宽度等)
$(window).bind('resize', function() {
$("#jqgrid").setGridWidth($(window).width());
}).trigger('resize');
Run Code Online (Sandbox Code Playgroud)
Jus*_*ier 53
作为后续行动:
此帖中显示的上一个代码最终被放弃,因为它不可靠.我正在使用以下API函数来调整网格大小,如jqGrid文档所建议的那样:
jQuery("#targetGrid").setGridWidth(width);
Run Code Online (Sandbox Code Playgroud)
要进行实际的大小调整,实现以下逻辑的函数将绑定到窗口的resize事件:
使用其父级的clientWidth计算网格的宽度,如果不可用,则计算其offsetWidth属性.
执行完整性检查以确保宽度变化超过x像素(以解决某些特定于应用程序的问题)
最后,使用setGridWidth()来更改网格的宽度
以下是处理调整大小的示例代码:
jQuery(window).bind('resize', function() {
// Get width of parent container
var width = jQuery(targetContainer).attr('clientWidth');
if (width == null || width < 1){
// For IE, revert to offsetWidth if necessary
width = jQuery(targetContainer).attr('offsetWidth');
}
width = width - 2; // Fudge factor to prevent horizontal scrollbars
if (width > 0 &&
// Only resize if new width exceeds a minimal threshold
// Fixes IE issue with in-place resizing when mousing-over frame bars
Math.abs(width - jQuery(targetGrid).width()) > 5)
{
jQuery(targetGrid).setGridWidth(width);
}
}).trigger('resize');
Run Code Online (Sandbox Code Playgroud)
和示例标记:
<div id="grid_container">
<table id="grid"></table>
<div id="grid_pgr"></div>
</div>
Run Code Online (Sandbox Code Playgroud)
jma*_*mav 36
自动调整大小:
对于jQgrid 3.5+
if (grid = $('.ui-jqgrid-btable:visible')) {
grid.each(function(index) {
gridId = $(this).attr('id');
gridParentWidth = $('#gbox_' + gridId).parent().width();
$('#' + gridId).setGridWidth(gridParentWidth);
});
}
Run Code Online (Sandbox Code Playgroud)
对于jQgrid 3.4.x:
if (typeof $('table.scroll').setGridWidth == 'function') {
$('table.scroll').setGridWidth(100, true); //reset when grid is wider than container (div)
if (gridObj) {
} else {
$('#contentBox_content .grid_bdiv:reallyvisible').each(function(index) {
grid = $(this).children('table.scroll');
gridParentWidth = $(this).parent().width() – origami.grid.gridFromRight;
grid.setGridWidth(gridParentWidth, true);
});
}
}
Run Code Online (Sandbox Code Playgroud)
这对我来说似乎很有效
$(window).bind('resize', function() {
jQuery("#grid").setGridWidth($('#parentDiv').width()-30, true);
}).trigger('resize');
Run Code Online (Sandbox Code Playgroud)
我正在使用960.gs进行布局,所以我的解决方案如下:
$(window).bind(
'resize',
function() {
// Grid ids we are using
$("#demogr, #allergygr, #problemsgr, #diagnosesgr, #medicalhisgr").setGridWidth(
$(".grid_5").width());
$("#clinteamgr, #procedgr").setGridWidth(
$(".grid_10").width());
}).trigger('resize');
// Here we set a global options
jQuery.extend(jQuery.jgrid.defaults, {
// altRows:true,
autowidth : true,
beforeSelectRow : function(rowid, e) { // disable row highlighting onclick
return false;
},
datatype : "jsonstring",
datastr : grdata, // JSON object generated by another function
gridview : false,
height : '100%',
hoverrows : false,
loadonce : true,
sortable : false,
jsonReader : {
repeatitems : false
}
});
// Demographics Grid
$("#demogr").jqGrid( {
caption : "Demographics",
colNames : [ 'Info', 'Data' ],
colModel : [ {
name : 'Info',
width : "30%",
sortable : false,
jsonmap : 'ITEM'
}, {
name : 'Description',
width : "70%",
sortable : false,
jsonmap : 'DESCRIPTION'
} ],
jsonReader : {
root : "DEMOGRAPHICS",
id : "DEMOID"
}
});
Run Code Online (Sandbox Code Playgroud)
//下面定义的其他网格......
如果你:
shrinkToFit: false
(平均固定宽度列)autowidth: true
您可以使用以下样式制作具有流体宽度的网格:
.ui-jqgrid {
max-width: 100% !important;
width: auto !important;
}
.ui-jqgrid-view,
.ui-jqgrid-hdiv,
.ui-jqgrid-bdiv {
width: auto !important;
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
101914 次 |
最近记录: |