I had a similar scenario: a list of customers with their own record data (address, phone, account balance, etc...) each customer also had an account with a set of "paid for" items. In other words I needed a grid of customers that could be rowexpanded to open their own "Account Grid" showing a grid of items with related data about the items, how much they paid, etc.
I slimmed out a bunch of disrelated configs and other code but here's an example of the view I used for the "outer" grid:
Ext.define('MyApp.view.CustomerGrid', {
extend: 'Ext.grid.Panel',
alias: 'widget.customergrid',
requires: [
'Ext.ux.RowExpander'
],
title: 'Customer Grid',
plugins: [{
ptype: 'rowexpander',
pluginId: 'rowexpander',
selectRowOnExpand: true,
// this gives each row a unique identifier based on record's "acct_no"
rowBodyTpl: [
'<div id="AccountGridRow-{acct_no}" ></div>'
],
// stick a grid into the rowexpander div whenever it is toggled open
toggleRow: function(rowIdx) {
var rowNode = this.view.getNode(rowIdx),
row = Ext.get(rowNode),
nextBd = Ext.get(row).down(this.rowBodyTrSelector),
hiddenCls = this.rowBodyHiddenCls,
record = this.view.getRecord(rowNode),
grid = this.getCmp(),
acctNo = record.get('acct_no'),
targetId = 'AccountGridRow-' + acctNo;
if (row.hasCls(this.rowCollapsedCls)) {
row.removeCls(this.rowCollapsedCls);
this.recordsExpanded[record.internalId] = true;
this.view.fireEvent('expandbody', rowNode, record, nextBd.dom);
if (rowNode.grid) {
nextBd.removeCls(hiddenCls);
rowNode.grid.doComponentLayout();
rowNode.grid.view.refresh();
} else {
// this is the store for the inner grid
Ext.create('Ext.data.Store', {
model: 'MyApp.model.Account',
proxy: {
type: 'ajax',
url: 'customers',
reader: 'json'
extraParams: {
account: acctNo
}
},
autoLoad: {
callback: function() {
// create the inner grid and render it to the row
nextBd.removeCls(hiddenCls);
var grid = Ext.create('MyApp.view.AccountGrid', { // <-- this is my "inner" grid view
renderTo: targetId,
store: this,
row: row
});
rowNode.grid = grid;
// I didn't want to listen to events from the inner grid
grid.suspendEvents();
}
}
});
}
} else {
row.addCls(this.rowCollapsedCls);
nextBd.addCls(this.rowBodyHiddenCls);
this.recordsExpanded[record.internalId] = false;
this.view.fireEvent('collapsebody', rowNode, record, nextBd.dom);
}
}
}],
columns: [/* a bunch of column configs for the outer grid... */],
store: Ext.getStore('StudentList') // <-- the outer grid store
});
Basically I just overrode the toggleRow
function to stick another grid (MyApp.view.AccountGrid
) into the rowexpander div.
This worked out very well and the app is completed now.
I have the data for the inner "account" grid in a cached object so that the ajax returns within 50 - 100 ms. If you had some kind of long query to get the inner grid data I could see this being unworkable.