1
votes

I need to create a dynamic gridpanel in ExtJS . I use an actioncolumn for this:

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');
},

Now I need to create the columns for this grid. The columns I need to make are in the rec.get('ResultFields'). When I use the console.log() I see this in the firebug:

[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
}]

How can I create columns with this?

1

1 Answers

1
votes

What seems to be a problem?

If you get information about columns before you create a grid - then create array or columns based on array of your fields. Something like this:

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')
   }));
});

And then just use that _cols when creating grid.