I have a dataview with a DragZone that uses a filtering XTemplate. When the row is dropped the wrong record is added to the DropZone store. But the sourceEl itself is correct...
Code:
tpl: new Ext.XTemplate(
'<ul class="programmes">',
'<tpl for=".">',
'<tpl if="channel_id == \''+channel.id+'\'">',
'<li class="{status} <tpl if="hidden">hidden</tpl>">',
'<span class="programStart">{start:date("H:i")}</span>',
'<a href="/programme/show/id/{id}">{title}</a>',
'</li>',
'</tpl>',
'</tpl>',
'</ul>',
{compiled: true, disableFormats: false}
)
Code:
function createDragZone(dataview){
dataview.dragZone = new Ext.dd.DragZone(dataview.getEl(), {
ddGroup: 'favGroup',
dataView: dataview,
getDragData: function(e){
var sourceEl = e.getTarget(dataview.itemSelector, 10); // This is correct
if (sourceEl) {
d = sourceEl.cloneNode(true);
d.id = Ext.id();
return dataview.dragData = {
ddel: d,
sourceEl: sourceEl,
repairXY: Ext.fly(sourceEl).getXY(),
sourceStore: dataview.store,
draggedRecord: dataview.getRecord(sourceEl) // This is wrong!!!
}
}
},
getRepairXY: function(){
return this.dragData.repairXY;
}
});
}
EDIT: I am using the same store for multiple dataviews.
EDIT: It works when I change the dropZones onContainerDrop into this:
Code:
...
...,
onContainerDrop : function(dropZone, evtObj, data) {
var href = Ext.fly(data.sourceEl).child('a', true).href;
var id = href.split('/').pop(); // The end part of href is the records id
var record = data.sourceStore.getById(id);
//var record = dropZone.dragData.draggedRecord;
var store = this.dataView.store;
this.dataView.store.add([record]);
this.dataView.store.sort('start', 'ASC');
return true;
}