PDA

View Full Version : Easy One - Small working snipit to improve



WinningJr
30 Sep 2014, 6:13 AM
The following snip of code is working great, but how would I get the grid without using getCmp and what else is done poorly? It is the onExpandBody function usingRowExpander in 4.2.3 in Architect (Grid promoted to a class and the onExpandBody is in the controller). Most of it is obviously developed from looking at a thousand examples:

onExpandBody: function(rowNode, record, expandRow) {
var containerName = "OrderRow" + record.get('OrderNumber'),
grid = Ext.getCmp ('grdOrders'); //go up from the node?


// See if the panel already exists from a previously expanded row and kill it.
var oldPanel = Ext.getCmp('pnlOrderRow');
if (oldPanel !== undefined) {
oldPanel.destroy();
}


// Collapse the prevoiusly expanded row
if (this.lastExpandedRowIdx !== undefined && this.lastExpandedRowIdx !== rowNode.rowIndex){
var rowex = grid.getPlugin('OrdersRowExpander');
var row = Ext.get(rowex.view.getNode(this.lastExpandedRowIdx));
row.addCls(rowex.rowCollapsedCls);
}


// store the currently expanded row index
this.lastExpandedRowIdx = rowNode.rowIndex;


// Create the panel inside the row
var holderPanel = Ext.create("SalesOrderHistory.view.pnlOrderRow");
holderPanel.render(containerName);
// I don't know why I have the following line :)
holderPanel.getEl().swallowEvent(['mouseover', 'mousedown', 'click', 'dblclick']);


// Load all the sotres on the details panel
var newURL = baseURL + 'jsonWeb.p?mode=OrderLines&orderNo=' + record.get('OrderNumber') +
'&SessionToken=' + SessionToken;
var ds = Ext.getStore('strOrderLine');
ds.proxy.url = newURL;
ds.load();


},

WinningJr
30 Sep 2014, 8:58 AM
Ooops. I can improve one comment. the swallowEvent prevents the actions from propagating up to the row in the parent grid, so you can double-click on something in the panel without the row closing on you.

slemmon
30 Sep 2014, 11:55 PM
Hi,

All seems fine. Instead of using getCmp you can get the grid reference using:



var grid = this.ownerCt;