2012-04-11 4 views
0

extjs에 동적 격자 패널을 작성해야합니다. 여기에 actioncolumn을 사용합니다 :extjs에 동적 격자 만들기

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

어떻게 내가 이것에 열을 생성 할 수 있습니다 ?

답변

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을 사용하십시오.