View Full Version : Adjusting height of grid container

16 Oct 2006, 4:01 PM
I'd like to be able to adjust the height of the grid container to fit the number of rows returned from a query (JSON). I've added the code in an onLoad handler which includes:

// set the height for the number of rows + the header height + room for scrollbar (i.e. rows*21px + 52px)
var ht = 52 + this.dataModel.getRowCount()*21;
YAHOO.util.Dom.setStyle('my-grid', 'height', '' + ht + 'px');

This works correctly, except that when the column widths are adjusted the horizontal scroll bar is not visible (if the new height is less than the default height of the container).

Also, if the default height of the container is too small for the number of rows then only the number of rows that can fit in the original height are displayed and no vertical scrollbar is displayed.

Obviously I'm missing something vital, so what is the correct way to adjust the height of the container so that the scroll bars work and all the rows fit correctly?

16 Oct 2006, 4:06 PM
Call grid.autoSize() after adjusting the size of the container. It will automatically adjust everything to fit the grid to the container.

16 Oct 2006, 4:28 PM

Thanks a lot.