PDA

View Full Version : How to load grid when inside a panel ?



duskandawn
2 Aug 2010, 10:38 AM
Hello All,
I have a searchPanel which looks like this :



Test.panel.testPanel = Ext.extend(Ext.Panel, {

initComponent: function() {
var config = {
layout: 'border',
bodyStyle: 'padding:5px',
items: [{
xtype: 'searchGrid',
region: 'center',
layout:'fit',
id:'gridRegion',
bodyStyle: 'padding:15px;'
},{
xtype: 'combo',
fieldLabel: 'TestFeeds',
triggerAction: 'all',
editable: false,
}

]

//searchGrid is my custom grid

Test.grid.searchGrid = Ext.extend(Ext.grid.GridPanel, {
title: 'Test feeds',
initComponent: function() {
var config = {
frame: true,
loadMask: true,....


In above case i have to load my grid on the basis of the combo box value attached to the searchPanel.
My question is how do i get hold of the searchGrid reference from here, and how do i call a custom loadGrid () function present in my grid object,

Please help

Thanks,

Reimius
2 Aug 2010, 11:59 AM
What you're trying to do here is create two different classes that will depend on each other? In which case it would make more sense to have one pass the other into it's own config as a reference so you can directly access the methods.

Then when you actually use these classes, you can pass the reference of the specific grid you want to refresh right into the panel you're creating.

darthwes
2 Aug 2010, 4:47 PM
I'm using this.items.items[0] because I'm comfortable that it works.
Ext.getCmp('gridRegion') or this.children.find seems better, but I'm just showing you an example solution.



var TestPanel = Ext.extend(Ext.Panel, {
initComponent: function() {
TestPanel.superclass.initComponent.apply(this, arguments);
var myCB = this.items.items[0].items.items[0]; //whatever, get a reference to the combobox
myCB.on('select', function(combo, rec, idx) {
var theGrid = combo.ownerCt; //that's a little better...
theGrid.store.baseParams.id = rec.get('id');
theGrid.loadGrid(); //or theGrid.store.load();
});
}
});


Sure hope that helps, it's always my pleasure to help people who post code. If this isn't what you want/doesn't make sense, keep on asking questions!

duskandawn
3 Aug 2010, 5:08 AM
Thank you, for your help.
I did later figure it out to use Ext.getCmp('gridRegion')to get access to my grid reference. I am still new to this technology, so was wondering if this was the correct way or i was doing something wrong here.

darthwes
3 Aug 2010, 6:59 AM
Ext.getCmp is fine. I assume it's O(log(n)) complexity, whereas someObj.[items|parent|children|ownerCt] would be O(1) (no lookups) if you can traverse your object hierarchy and find what you're looking for relative to someObj (this, a parameter, a panel).

If I were you, I would stick with getCmp until I had written enough EXT to feel comfortable with traversing the object hierarchy using ownerCt/items.

The big guns can probably explain those things, but if you're like me, Ext.getCmp works so I'd stick with it. The end user won't be able to discern the few milliseconds of difference.