EXTJS RoW Widget - 旧数据被Store的新数据取代

时间:2018-02-02 08:57:17

标签: extjs widget store expansion

我正在研究EXTJS。我在Row Widget中遇到了问题,我已经起诉扩展Grid。我有一个网格显示来自一个表的数据,一个扩展其中一个行,传递密钥以显示另一个表中的扩展行,其值与传递密钥的值相同。

我面临的问题是每当use扩展两行时,新数据就会被加载并反映在旧的扩展行中。

如果需要其他任何内容,请告诉我?

1 个答案:

答案 0 :(得分:1)

为此,您需要在商店内使用alias:'store.storename',在grid内部,您需要使用该商店,如下例所示: -

store:{
   type:'storealias'
}

因此它将始终为扩展网格创建新实例。

FIDDLE 中,我根据您的需要创建了一个演示。我希望这能指导/帮助您实现您的要求。

CODE SNIPPET

Ext.application({
    name: 'Fiddle',

    launch: function () {
        Ext.define('ExpandStore', {
            extend: 'Ext.data.Store',
            alias: 'store.expandstore',
            proxy: {
                type: 'ajax',
                url: '',
                reader: {
                    type: 'json',
                    rootProperty: 'data',
                    keepRawData: true
                }
            }
        })
        Ext.create({
            renderTo: Ext.getBody(),
            title: 'Main Grid',
            xtype: 'gridpanel',
            width: 600,
            height: 300,
            layout: 'fit',
            store: Ext.create('Ext.data.Store', {
                data: [{
                    value1: 'Test 1',
                    id: 'Record one',
                    value2: 'Test 2'
                }, {
                    value1: 'Test 3',
                    id: 'Record two',
                    value2: 'Test 4'
                }]
            }),
            columns: [{
                dataIndex: 'value1',
                flex: 1,
                text: 'Column One'
            }, {
                dataIndex: 'value2',
                flex: 1,
                text: 'Column Two'
            }],
            listeners: {
                rowdblclick: 'onEfxAmendedTradesGridPanelIdRowDblClick'
            },
            plugins: [{
                ptype: 'rowwidget',
                onWidgetAttach: function (plugin, grid, record) {
                    var url = 'data1.json';
                    /*
                     * Herer I am putting condition on basis of record id
                     * In you case may you will call same url but diffrent id on server side so you Just need to send
                     * that id or may you will pas extra parameter inside of store
                     * For more details you can refer senha docs
                     */
                    if (record.get('id') == 'Record two') {
                        url = 'data2.json'
                    }
                    //if store is already loaded then no need to load again if you need you can remove this condition.
                    if (!grid.getStore().isLoaded()) {
                        grid.getStore().load({
                            url: url
                        })
                    }
                },
                rowBodyTpl: ['rowBodyTpl'],
                widget: {
                    xtype: 'gridpanel',
                    width: '100%',
                    autoLoad: false,
                    reference: 'AuditGridPanelRef',
                    scrollable: 'both',
                    bind: {
                        title: 'Expand ID is "{record.id}"'
                    },
                    store: {
                        type: 'expandstore' // it will create new instance of expandstore for every creation of grid
                    },
                    columns: [{
                        dataIndex: 'value1',
                        flex: 1,
                        text: 'Column One'
                    }, {
                        dataIndex: 'value2',
                        flex: 1,
                        text: 'Column two'
                    }]
                }
            }]
        })

    }
});