PDA

View Full Version : dataview.getRecord(sourceEl) returns wrong record



Dr. Flink
27 Sep 2009, 3:45 AM
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...


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

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:

...
...,
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;
}

Animal
27 Sep 2009, 5:37 AM
A Record may only be a member of one Store at a time. You must copy the Record and add the copy to the other Store.

naggy
7 Oct 2011, 12:56 AM
Hi,

I've got the same issue in ExtJS 4.

I use multiple views that use the same store. This shouldn't be an issue?

I rather think that the problem has to do with the fact that records are filtered inside the XTemplate (using an if clause).

Seems like getRecord uses the index of the element in the view rather than the id of the underlying record, which will return the wrong record in case of filtering...

Thanks,
Markus

Corcho
12 Feb 2014, 12:52 PM
Same problem here:
Dataview filtered within the tpl by an "if " condition makes the "record" parameter on "itemclick" event to be wrong. Example: if, inside the tpl, I filter the first two records of a total of 10, then I select the last one (apparently the 10th), the itemclick event is going to receive the 8th record because is taking it from the store and not the dataview.

Using the "filter" functions of the store avoids this problem. Although, it would be helpfull to have a solution filtering inside tpl.

Thx.