【问题标题】:create a dynamic grid in extjs在 extjs 中创建一个动态网格
【发布时间】:2012-04-11 09:19:10
【问题描述】:

我需要在 ExtJS 中创建一个动态的gridpanel。我为此使用actioncolumn:

handler: function(view, rowIndex, colIndex, item, e) {
    var tabs = Ext.getCmp('northPanel');
    var rec = view.getStore().getAt(rowIndex);

    modelFactory(rec.get('Reference'), rec.get('ResultFields'));

    console.log(rec.get('ResultFields'));
    console.log('start adding tab');
    tabs.add({
        title: 'Report: ' + rec.get('Reference'),
        closable: true,
        dockedItems: [{
            xtype: 'toolbar',
            dock: 'top',
            items: [{
                xtype: 'tbfill'
            }, {
                xtype: 'button',
                text: 'Export report'
            }, {
                xtype: 'button',
                text: 'Refresh data'
            }]
        }],
        xtype: 'tabpanel',
        items: [{
            xtype: 'gridpanel',
            title: 'Gridview',
            forceFit: true,
            store: ND.store,
            columns: []
        }]
    });

    console.log('tab created');
},

现在我需要为这个网格创建列。我需要制作的列在rec.get('ResultFields') 中。当我使用console.log() 时,我在萤火虫中看到了这个:

[Object {
    name = "currentSimAllocationByCcu", type = "textfield", format = null
}, Object {
    name = "wanNumber", type = "textfield", format = null
}, Object {
    name = "carrierName", type = "textfield", format = null
}, Object {
    name = "dataPackageName", type = "textfield", format = null
}, Object {
    name = "simIccid", type = "textfield", format = null
}, Object {
    name = "expiryTime", type = "textfield", format = null
}, Object {
    name = "bytesRx", type = "textfield", format = null
}, Object {
    name = "bytesTx", type = "textfield", format = null
}]

如何使用它创建列?

【问题讨论】:

    标签: dynamic extjs grid


    【解决方案1】:

    似乎有什么问题?

    如果您在创建网格之前获得有关列的信息 - 然后根据您的字段数组创建一个或多个列。像这样的:

    var _cols = [],
        _flds = rec.get('ResultFields');
    
    Ext.Array.each(_flds, function(f) {
       _cols.push(Ext.create('Ext.grid.column.Column', {
          text: f.get('name'),
          dataIndex: f.get('name')
       }));
    });
    

    然后在创建网格时使用_cols。

    【讨论】:

      猜你喜欢
      • 2012-06-15
      • 2015-12-10
      • 2019-03-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多