2012-07-07 65 views
0

ExtJS4Treenode到GridView

我試圖將treenode移動到gridpanel。我希望將其關聯數據插入此處。但是,無論何時移動treenode,它都會在該位置創建一個空行。 我創建了樹:

var treeData = { 
     text: 'Business Processes', 
     children:[ 
      {text: 'Process7', lob: 'Lob7', leaf:true}, 
      {text: 'Process8', lob: 'Lob8', leaf:true}, 
      {text: 'Process9', lob: 'Lob9', leaf:true}, 
      {text: 'Process10', lob: 'Lob10', leaf:true}, 
      {text: 'Process11', lob: 'Lob11', leaf:true}, 
      {text: 'Process12', lob: 'Lob12', leaf:true} 
     ] 
    }; 
    bpTreeStore = Ext.create('Ext.data.TreeStore',{}); 
    bpTreeStore.setRootNode(treeData); 

    new Ext.TreePanel({ 
     id:'businessProcessTree', 
     store : bpTreeStore, 
     viewConfig: { 
      plugins:{ 
       ptype: 'treeviewdragdrop', 
       dropGroup: 'dragGroup', 
       dragGroup: 'dragGroup', 
       dragText: 'Place the node to grid' 
       } 
     } 
    }); 

和電網作爲

Ext.define('BusinessProcessStoreModel',{ 
extend:'Ext.data.Model', 
fields: [ 
{ name:'businessProcessName', type:'string' }, 
{ name:'businessProcessLob', type:'string' } 
] 
}); 
bpMappingStore = Ext.create('Ext.data.ArrayStore', { 
     model:'BusinessProcessStoreModel', 
     data:[ 
      ['Process1', 'Lob1'], 
      ['Process2', 'Lob2'], 
      ['Process3', 'Lob3'] 
     ] 
    }); 
var bpMappingGrid = Ext.create('Ext.grid.Panel',{ 
     id:'bpGridPanel', 
     region:'center', 
     frame:true, 
     layout:'fit', 
     height:300, 
     columns:[ 
     { header:'Process Name', dataIndex:'businessProcessName' }, 
     { header:'Process Lob', dataIndex:'businessProcessLob' } 
     ], 
     store:bpMappingStore, 
     viewConfig: { 
      plugins:{ 
       ptype: 'gridviewdragdrop', 
       dropGroup: 'dragGroup', 
       dragGroup: 'dragGroup', 
       dragText: 'Place the node to grid' 
       }, 
      listeners: { 
       drop: function(node, data, overModel, dropPosition) 
       { 
        var position = (dropPosition=='after'?overModel.index + 1: overModel.index -1); 
        Ext.getCmp('bpGridPanel').store.insert(position, [[data.records[0].data.text, 'LOB']]); 
//data.records[0].data.lob is undefined don't know why 

       } 
      } 
     } 
    }); 

請告訴我如何借鑑「文」和樹節點的「吊射」被插入到網格面板的兩列。

我在這裏創建了我自己的

回答

1

我解決了這個問題。確保被拖動的Treenode必須包含網格正在使用的模型中的屬性。

這裏,treedata可以被定義爲

var treeData = { 
     text: 'Business Processes', 
     children:[ 
      {text: 'Process7', businessProcessName: 'Process7', businessProcessLob: 'Lob7', leaf:true}, 
      {text: 'Process8', businessProcessName: 'Process8', businessProcessLob: 'Lob8', leaf:true}, 
      {text: 'Process9', businessProcessName: 'Process9', businessProcessLob: 'Lob9', leaf:true}, 
      {text: 'Process10',businessProcessName: 'Process10', businessProcessLob: 'Lob10', leaf:true}, 
      {text: 'Process11', businessProcessName: 'Process11', businessProcessLob: 'Lob11', leaf:true}, 
      {text: 'Process12', businessProcessName: 'Process12', businessProcessLob: 'Lob12', leaf:true} 
     ] 
    }; 
    this.bpTreeStore = Ext.create('Ext.data.TreeStore',{root: this.treeData}); 

但是,當我們指定這個treedata對象的treestore。它刪除新的屬性(businessProcessName和businessProcessLob)。

所以要添加它們,可以運行一個循環。

for(var index in treeData.children) 
{ 
    this.bpTreeStore.tree.root.childNodes[index].data.businessProcessName = treeData.children[index].businessProcessName; 
    this.bpTreeStore.tree.root.childNodes[index].data.businessProcessLob = treeData.children[index].businessProcessLob; 
} 

在此之後,拖着工作正常:)