View Full Version : Adding Grid to ContentPanel

20 Nov 2006, 4:05 PM
I have a center region using BorderLayout. I would like to add a Grid to the center region through a ContentPanel. I've tried ContentPanel and GridPanel but cannot seem to get the Grid to auto size columns. Any ideas what I'm doing wrong?

_dh.append('app', {tag: 'div', id: 'order-list'});
var ordersGrid = new YAHOO.ext.grid.Grid('order-list', dm, cm);

var ordersPanel = new YAHOO.ext.GridPanel(ordersGrid, {title:'Orders', fitToFrame:true, closable: true});
_layout.add('center', ordersPanel);

20 Nov 2006, 4:27 PM
Don't specify width on your columnmodel entries

20 Nov 2006, 4:42 PM
I don't. :(

var columns = [
{header: 'ID', sortable: true},
{header: 'Date', sortable: true},
{header: 'Price', sortable: true, renderer: money},
{header: 'Status', sortable: true}

20 Nov 2006, 4:49 PM
Hmm.. My example built a ContentPanel instead of GridPanel and then just rendered the grid into another div inside the contentpanel div. Not sure why there would be a difference, unless it's an issue of not specifying height/width on the grid container via CSS.

21 Nov 2006, 3:37 AM
I don't see autoSizeColumns set to true or a call to grid.getView().autoSizeColumns(). Is that somewhere else?

23 Nov 2006, 6:50 AM
Thanks, Jack. That worked for me. I put that line of code in the callback handler to the data model load() method. Once the data is loaded, the grid adjusts the columns nicely inside the content panel.

When I resize the splitter on an east or west panel, or collapse an east or west panel, the grid doesn't readjust. Is there a listener I can wire up for that?

23 Nov 2006, 11:18 AM
Yep. Take a look at at the events under: