从父网格获取值,将其用作子网格ext.js 4中的标题

时间:2013-09-19 10:03:10

标签: extjs grid selection extjs4.1 title

我想要做的操作并不容易。我有第一个网格(或表)和第二个网格,生成点击第一个表的每一行中出现的单元格。它接受第一个表的参数,并显示生成表的json的其他一些内容。

第二个表包含在第一个表的一列中,它由ajax调用生成:

Ext.create('Ext.window.Window' etc. etc.

问题 是我想要获取第一个表的行的名称并将其用作第二个表的名称,该表位于第一个表中。我找到了一些有用的建议(12)但是找到了“当前”表的工作,而不是我的具体情况。有人可以帮忙吗?

我使用的代码如下,但阅读时间很长,所以我怀疑它是否有用。

// create the Grid
var grid = Ext.create('Ext.ux.LiveSearchGridPanel', {
    store: store1,
    stateful: true,
    collapsible: true,
    multiSelect: true,
    stateId: 'stateGrid',
    columns: [
        {
            text     : 'id',
            flex     : 1,
            sortable : true,
            dataIndex: 'id'
        },
        {
            text     : 'buyer_member_id',
            width    : 75,
            sortable : true,
            dataIndex: 'buyer_member_id'
        },
        {
            text     : 'Client Name',
            width    : 200,
            sortable : true,
            dataIndex: 'name'
        },
        {
            xtype : 'actioncolumn',
            width : '5%',
            sortable : false,
            items : [{
                icon : '../static/accept.gif',
                tooltip : 'See Admants',
                handler : function(grid, rowIndex, colIndex){
                    var row = grid.getStore().getAt(rowIndex);
                     var buyer_member_id = row.data.buyer_member_id;
                    Ext.Ajax.defaultHeaders = {
                        "Content-Type": "application/x-www-form-urlencoded; charset=UTF-8"
                    };
                    Ext.Ajax.request({
                        method : "GET",     
                        url: '/admants/?buyer_member_id='+ buyer_member_id,
                        success : function(response) {
                            var obj = response;
                            try {
                                obj = Ext.decode(response.responseText);
                            } catch (error) {alert("Errore nella decodifica del file json");}
                            if (obj) { 
                                Ext.define('Admants', {
                                extend: 'Ext.data.Model',
                                fields: [
                                      {name: 'id',    type: 'int', convert: null,    defaultValue:undefined},
                                      {name: 'name',  type: 'string', convert:null,  defaultValue:undefined},
                                      {name: 'group', type: 'string', convert:null,  defaultValue:undefined}
                                ],
                                idProperty: 'id'
                                });
                                var groupingFeature = Ext.create('Ext.grid.feature.Grouping',{
                                        groupHeaderTpl: 'Group: {name} ({rows.length} Item{[values.rows.length > 1 ? "s" : ""]})'
                                });
                                var Admantstore = Ext.create('Ext.data.Store', {
                                        autoLoad: true,
                                        storeId: 'Admants',
                                        sorters: ['id', 'name','group'],
                                        groupField: 'group',
                                        fields: ['id','name','group'],
                                        data : obj,
                                        model: 'Admants',
                                        proxy: {
                                            type: 'memory',
                                            reader: {
                                                type: 'json',
                                                root: 'admants'
                                            }
                                        }
                                    });
                                Ext.create('Ext.window.Window', {
                                title: 'Admants', //this line has to be changed
                                height: 200,
                                width: 400,
                                layout: 'fit',
                                items: {  
                                xtype: 'grid',
                                border: false,
                                store: Admantstore,
                                features: [groupingFeature],
                                columns: [
                                        {
                                            text     : 'id',
                                            flex     : 1,
                                            sortable : true,
                                            dataIndex: 'id'
                                        },
                                        {
                                            text     : 'name',
                                            width    : 300,
                                            sortable : true,
                                            dataIndex: 'name'
                                        }],
                                }}).show();
                            } else {
                            alert("Invalid response");
                            }
                        },
                        failure : function(response) {
                            alert("Data request failed");
                        }
                    }); 
                }
            }]
        }
    ],
    height: 350,
    width: 600,
    title: 'Member Data Sharing',
    renderTo: 'grid-example1',
    viewConfig: {
        stripeRows: true,
        enableTextSelection: true
    }
});

});

1 个答案:

答案 0 :(得分:0)

好的,然后我使用了一条线,它使用了第一个(父)表的存储数据,并被分配给一个可以在所有函数中使用的变量。这两条线就是诀窍:

var row = grid.getStore().getAt(rowIndex);
var buyer_member_id = row.data.buyer_member_id;
var AdmantClient = row.data.name

然后我使用AdmantClient变量作为第二个(子)表/网格的标题。 希望这会有所帮助。

相关问题