PDA

View Full Version : Can't launch grid view from controller



john_dm
17 May 2013, 9:52 AM
I need to open a view from my controller, but it is not working when the view is a grid. If I change the view to a Window, it works fine. This is the controller code that should launch the view...



Ext.widget('reportwindow', {
title: tab.title
});


Here is the view (a basic grid, taken from one of the examples in the docs...


Ext.define('RB.view.reportWindow', {
extend: 'Ext.grid.Panel',
alias: 'widget.reportwindow',


title: 'Users',
store: {
fields: ['name', 'email'],
data : [
{name: 'Ed', email: 'ed@sencha.com'},
{name: 'Tommy', email: 'tommy@sencha.com'}
]
},
columns: [
{header: 'Name', dataIndex: 'name', flex: 1},
{header: 'Email', dataIndex: 'email', flex: 1}
]
});


So when I run this, I get nothing. No errors in the log at all. However, if I change the view to be a window component with a grid inside, it works fine. Here is the code that works.



Ext.define('RB.view.reportWindow', {
extend: 'Ext.window.Window',
alias: 'widget.reportwindow',


width: '100%',
height: '100%',
closable: true,
minimizable: true,
autoShow: true,


initComponent: function() {
this.callParent();


var grid = Ext.create('Ext.grid.Panel', {
title: 'Users',
store: {
fields: ['name', 'email'],
data : [
{name: 'Ed', email: 'ed@sencha.com'},
{name: 'Tommy', email: 'tommy@sencha.com'}
]
},
columns: [
{header: 'Name', dataIndex: 'name', flex: 1},
{header: 'Email', dataIndex: 'email', flex: 1}
]
});


this.add(grid);
}
});


Does anyone have any idea why this won't work for a grid?

tobiu
17 May 2013, 9:58 AM
a grid is an extension of a container which needs to be inside another container (viewport, container, window,...). a window is a floating container (panel) which has build in methods for showing / hiding it.

so in case you want to show a floating grid, the approach to put it inside a window is fine.

you should set a layout for your window though (like layout: "fit").

dynamically adding a grid to an existing container works fine.

best regards
tobiu

john_dm
17 May 2013, 10:04 AM
Ok, that makes sense. Thanks tobiu!