3

如何解决带有子网格的网格行扩展器?以纯文本形式获取价值可以正常工作。

有什么方法可以在 Grid 中创建 Grid 以从 JSON 数据中获取价值?

我想使用 MVC 架构创建这个结构。

Ext.define('CSApp.view.ContentGrid',
{
 extend: 'Ext.grid.Panel',
 store: 'Details',
 width: 840,
 height:45,
 initComponent: function()
 {
 this.columns = [
 {header: 'TASK ID', dataIndex: 'taskID', flex:1},
 {header: 'ITEM', dataIndex: 'name', flex:1},
 {header: 'EXISTING VALUE', dataIndex: 'value', flex:1},
 {header: 'NEW VALUE', dataIndex: 'newValue', flex:1}];
 this.callParent(arguments);
 }
});
4

2 回答 2

8

我有一个类似的场景:拥有自己的记录数据(地址、电话、帐户余额等)的客户列表,每个客户也有一个包含一组“付费”项目的帐户。换句话说,我需要一个可以行扩展的客户网格,以打开他们自己的“帐户网格”,显示一个项目网格,其中包含有关项目的相关数据、他们支付的金额等。

我精简了一堆不相关的配置和其他代码,但这是我用于“外部”网格的视图示例:

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

});

基本上我只是重写了将toggleRow另一个网格 ( MyApp.view.AccountGrid) 粘贴到 rowexpander div 中的函数。

效果很好,应用程序现已完成。

我在缓存对象中有内部“帐户”网格的数据,以便 ajax 在 50 - 100 毫秒内返回。如果您有某种长查询来获取内部网格数据,我会发现这是行不通的。

于 2012-10-31T18:26:56.527 回答
2

RowExpander 不允许嵌套网格结构。它所允许的只是在行正文中插入任何 HTML。这意味着您可以在展开的行内创建一个 HTML 表格,但它不是另一个 Ext Grid。

于 2012-10-31T16:27:34.850 回答