0

For a long time I am looking for an answer to how to make the fluid height in jqGrid, but I still have not found it.

So, I need fluid height.

I know how to make fluid width:

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

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

I tried with

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

but that is not working.

Is there a solution?

Moslem Ben Dhaou
  • 6,897
  • 8
  • 62
  • 93
Deks
  • 21
  • 1
  • 5
  • 1
    I personally prefer just to use `height:'auto'`. If you need have the pager always visible you can consider to use toppager (see [here](http://stackoverflow.com/questions/4402455/unable-to-position-pager-navigation-bar-above-jqgrid/4402903#4402903) for example). It the way you would have not the same behavior as you described, but another one having the same user experience. – Oleg Oct 11 '11 at 07:39

2 Answers2

1

I found a solution for my problem. Here is the code (works in 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);
}
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Deks
  • 21
  • 1
  • 5
0

I appreciate this is an old thread - but here's a CSS (and therefore smoother) solution.

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);
}

An example of this in action : http://jsfiddle.net/Ba5yK/16/

pphillips001
  • 405
  • 3
  • 4