Reputation: 2668
ExtJS4
I'm trying to move a treenode to gridpanel. I want its associated data to be inserted here. But whenever I move the treenode, it creates an empty row at that position. I've created the tree as:
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'
}
}
});
And the grid as
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
}
}
}
});
Please tell me how I refer to the 'text' and 'lob' of the treenode to be inserted into the two columns of the gridpanel.
Here I've created my own
Upvotes: 0
Views: 423
Reputation: 2668
I solved the problem. Make sure that the Treenode being dragged must contain the attributes in the model which the grid is using.
Here, treedata can be defined as
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});
But when we assign this treedata object to the treestore. It removes the new attributes (businessProcessName and businessProcessLob).
So to add them, a loop can be run.
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;
}
After this, dragging works fine :)
Upvotes: 1