如何制作jqGrid流体高度?

时间:2011-10-11 07:16:41

标签: jqgrid height jqgrid-php

很长一段时间我一直在寻找如何在jqGrid中制作流体高度的答案,但我还是没有找到它。

所以,我需要流体高度

我知道如何制作流体宽度:

jQuery(window).resize(function(){
gridId = "grid";

gridParentWidth = $('#gbox_' + gridId).parent().width();
$('#' + gridId).jqGrid('setGridWidth',gridParentWidth);
})

我试过

gridParentHeight = $('#gbox_' + gridId).parent().height();
$('#' + gridId).jqGrid('setGridHeight',gridParentHeight);

但这不起作用。

有解决方案吗?

2 个答案:

答案 0 :(得分:1)

我找到了解决问题的方法。这是代码(适用于Firefox):

winHeight = window.innerHeight;
wHeight = winHeight - 90;

$("#grid").jqGrid('setGridHeight',wHeight);

jQuery(window).resize(function(){
    gridId = "grid";
    gridWidth = $('#gbox_' + gridId).parent().width();

    $('#' + gridId).jqGrid('setGridWidth',gridWidth);
    if(wHeight < 110){  //Height of five rows in grid is 110 pixels.
        wHeight = 110;
        $('#'+ gridId).jqGrid('setGridHeight',wHeight);
    }
    else {
        $('#'+ gridId).jqGrid('setGridHeight',wHeight);
}

答案 1 :(得分:0)

我很欣赏这是一个旧线程 - 但这是一个CSS(因此更顺畅)的解决方案。

beforeRequest: function () {
  setTimeout(function () {
    var gridName = this.id;
    $('#gbox_' + gridName).css({
      position: 'absolute',
      top: 0,
      bottom: $('#gbox_' + gridName + ' .ui-pager-control').outerHeight() + 'px',
      width: '100%',
      height: '100%'
    });
    $('#gbox_' + gridName + ' .ui-jqgrid-view').css({ 'height': '100%' });
    $('#gbox_' + gridName + ' .ui-jqgrid-bdiv').css({
      position: 'absolute',
      top: $('#gbox_' + gridName + ' .ui-jqgrid-titlebar').outerHeight() + $('#gbox_' + gridName + ' .ui-jqgrid-hbox').outerHeight() + 'px',
      bottom: 0,
      left: 0,
      right: 0,
      height: '',
      width: ''
    });
  }, 100);
}

此实例的一个示例:http://jsfiddle.net/Ba5yK/16/