views:

1211

answers:

4

I want my jqGrid to shrink and expand based on the number of rows it has. Let say it currently has 10 rows, the height of the jqGrid will shrink to 10 rows (so that no gaping empty rows is exposed).

If however there are too many rows, the height of the grid will expand to a maximum 'height' value and a scroll bar will appear.

+4  A: 

That's built into the grid. You set height to 100%. There's a demo on this page if you go "Advanced -> Resizing.

Craig Stuntz
Is this new feature in 3.6? How to set maximum height? I wouldn't want the grid to fill the entire screen either.
Rosdi
No, it's much older than 3.6. Maximum height isn't supported AFAIK (other than limiting row count); you'll have to work harder for that or put it in something scrollable.
Craig Stuntz
I can't limit the row count since it is not within my control. However I am accepting this answer since it partially fulfills my need and there is no other answer.
Rosdi
+1  A: 

call the below function from afterInsertRow and when deleting a row:

function adjustHeight(grid, maxHeight){
    var height = grid.height();
    if (height>maxHeight)height = maxHeight;
    grid.setGridHeight(height);
}
Pete Amundson
+1  A: 

try :

jQuery(".ui-jqgrid-bdiv").css('height', jQuery("#bigset").css('height'));

in jQGrid callback function, loadComplete.

where bigset is grid table id I used.

This worked perfectly for me.

Amit Aggarwal
A: 

Though the height 100% worked fine in the demo, it didn't work for me. The grid became much bigger, maybe it tried to occupy the parent div's height. Amit's solution worked perfectly for me, thanks! (I'm new as a contributor here, and so need a higher 'reputation' to mark any votes up :) )

msanjay