1. #1
    Sencha User
    Join Date
    Aug 2008
    Location
    Gothenburg
    Posts
    157
    Vote Rating
    2
    Dr. Flink is on a distinguished road

      0  

    Default dataview.getRecord(sourceEl) returns wrong record

    dataview.getRecord(sourceEl) returns wrong record


    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;
        }
    Last edited by Dr. Flink; 27 Sep 2009 at 4:28 AM. Reason: Note

  2. #2
    Sencha - Ext JS Dev Team Animal's Avatar
    Join Date
    Mar 2007
    Location
    Notts/Redwood City
    Posts
    30,508
    Vote Rating
    56
    Animal has a spectacular aura about Animal has a spectacular aura about Animal has a spectacular aura about

      0  

    Default


    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.

  3. #3
    Sencha User
    Join Date
    Feb 2011
    Posts
    34
    Vote Rating
    0
    naggy is on a distinguished road

      0  

    Default


    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

  4. #4
    Sencha User
    Join Date
    Apr 2012
    Posts
    16
    Vote Rating
    0
    Corcho is on a distinguished road

      0  

    Default


    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.

Thread Participants: 3