2016-12-15 22 views
5

如何從另一面板拖動面板項目?如何將名稱1拖動到名稱6面板

例如:我想拖動Name1到Name 6面板。當我嘗試按shift + mousescrollkey時,它鬆動拖動項目。

感謝提前:)

小提琴:https://fiddle.sencha.com/#fiddle/1hgf&view/editor

Ext.application({ 
    name: 'Fiddle', 

    launch: function() { 
     Ext.define('myColumn', { 
      extend: 'Ext.view.View', 
      xtype: 'mycolumn', 

      padding: 5, 
      margin: 5, 
      style: 'background-color: #f2f2f2;', 

      itemSelector: 'div.nameselector', 
      tpl: ['<tpl for=".">', '<div class="nameselector<tpl if="isTemp"> temp</tpl>">', '{name}', '</div>', '</tpl>'], 

      listeners: { 
       render: function(me) { 
        var tempRec = null; 

        // Create drag zone 
        this.dragZone = new Ext.dd.DragZone(me.getEl(), { 
         // On receipt of a mousedown event, see if it is within a DataView node. 
         // Return a drag data object if so. 
         getDragData: function(e) { 
          // Use the DataView's own itemSelector (a mandatory property) to 
          // test if the mousedown is within one of the DataView's nodes. 
          var sourceEl = e.getTarget(me.itemSelector, 10); 
          // If the mousedown is within a DataView node, clone the node to produce 
          // a ddel element for use by the drag proxy. Also add application data 
          // to the returned data object. 
          if (sourceEl) { 
           d = sourceEl.cloneNode(true); 
           d.id = Ext.id(); 
           return { 
            ddel: d, 
            sourceEl: sourceEl, 
            sourceZone: me, 
            sourceStore: me.store, 
            repairXY: Ext.fly(sourceEl).getXY(), 
            draggedRecord: me.getRecord(sourceEl) 
           } 
          } 
         }, 
         getRepairXY: function() { 
          return this.dragData.repairXY; 
         } 
        }); 

        this.dropZone = new Ext.dd.DropZone(me.getEl(), { 
         // Helper method to return correct class string if drop 
         // is permitted or not. 
         getAllowed: function(allowed) { 
          var proto = Ext.dd.DropZone.prototype; 
          return allowed ? proto.dropAllowed : proto.dropNotAllowed; 
         }, 

         notifyOver: function(source) { 
          return this.getAllowed(source !== me.dragZone); 
         }, 

         // Called when dragged element is over a drop zone. 
         // If allowed, make a copy of the dragged record to 
         // display in the zone (temporarily) by adding the record 
         // to the column store. 
         notifyEnter: function(source, e, data) { 
          var allowed = source !== me.dragZone; 
          if (allowed) { 
           tempRec = data.draggedRecord.clone(); 
           // Set record field 'isTemp' to true which will cause the dataview 
           // template to use the 'temp' style defined in app.css 
           tempRec.set('isTemp', true); 
           me.getStore().add(tempRec); 
          } 
          return this.getAllowed(allowed); 
         }, 

         // Called when the dragged element leaves a container. Remove 
         // the temporary record from the column store, removing the placeholder. 
         notifyOut: function(source, e, data) { 
          if (tempRec) { 
           me.getStore().remove(tempRec); 
          } 
         }, 

         // When a dragged source is over a container, 
         // set the appropriate drop style for the dragged element. 
         onContainerOver: function(source, e, data) { 
          return this.getAllowed(source === me.dragZone); 
         }, 

         // When the element is dropped on a column, check to see 
         // if we are dropping on the same column or not. If not, 
         // then remove record from source column, add record to 
         // drop column. 
         onContainerDrop: function(source, e, data) { 
          var overSame = source == me.dragZone, 
           dragData = source.dragData; 

          if (overSame) { 
           // Do not allow drop over same zone 
           // Return false to do a repair. 
           return false; 
          } 

          var rec = dragData.draggedRecord; 
          dragData.sourceStore.remove(rec); 
          me.getStore().add(rec); 

          // Clear temporary record 
          tempRec = null; 

          return true; 
         } 
        }); 
       } 
      } 
     }); 

     Ext.create('Ext.panel.Panel', { 
      renderTo: Ext.getBody(), 
      plugins: 'viewport', 
      scrollable: 'horizontal', 
      layout: { 
       type: 'hbox', 
       align: 'stretch' 
      }, 
      defaults: { 
       'width': 300 
      }, 
      items: [{ 
       xtype: 'mycolumn', 
       store: { 
        fields: ['name'], 
        data: [{ 
         name: 'Name 1' 
        }] 
       } 
      }, { 
       xtype: 'mycolumn', 
       store: { 
        fields: ['name'], 
        data: [{ 
         name: 'Name 2' 
        }] 
       } 
      }, { 
       xtype: 'mycolumn', 
       store: { 
        fields: ['name'], 
        data: [{ 
         name: 'Name 3' 
        }] 
       } 
      }, { 
       xtype: 'mycolumn', 
       store: { 
        fields: ['name'], 
        data: [{ 
         name: 'Name 4' 
        }] 
       } 
      }, { 
       xtype: 'mycolumn', 
       store: { 
        fields: ['name'], 
        data: [{ 
         name: 'Name 5' 
        }] 
       } 
      }, { 
       xtype: 'mycolumn', 
       store: { 
        fields: ['name'], 
        data: [{ 
         name: 'Name 6' 
        }] 
       } 
      }] 
     }) 
    } 
}); 
+0

可以autoscroll成爲解決方案嗎? –

+0

@ Mr.Bruno autoScoll:true也不起作用 –

+0

我已經嘗試了很多解決方案,並且沒有人想自動滾動您的面板,爲我+1,我們將等待其他slurif –

回答

3

它在ExtJS的版本6.0.2錯誤的dragZone滾動配置不起作用。 panel.scrollBy()也不能滾動該面板。我認爲你將不得不更新你的框架。

當您更新到6.2.0.589時,scrollBy函數將開始工作。您可以將鼠標事件添加到每個列,當您結束時,請滾動主面板。

containermouseover: function (me) { 
    var panel = Ext.first('#myMainPanel'); 
    panel.scrollBy(me.getX() - panel.getWidth()/4, 0, true); 
}, 

當你更新到6.2.0.981在dragZone的scroll配置將開始工作。

this.dragZone = new Ext.dd.DragZone(me.getEl(), { 
    ... 
    // this doesn't work in 6.0.2 but works in 6.2.0.981 
    scroll: true 
}); 

我的小提琴 https://fiddle.sencha.com/#view/editor&fiddle/1qse

但現在當你持有一個項目,您滾動入列,它的懸浮窗這是不是在視圖之前,列未註冊爲一個懸浮窗,你可以放棄物品。 notifyOver事件不會被調用。

而且我得到了相同的結果時,我與http://examples.sencha.com/extjs/6.2.0/examples/classic/dd/dragdropzones.html

我認爲這是另一個ExtJS的錯誤嘗試。

一般來說,我不認爲這是很好的用戶體驗設計,當你使用拖放時需要滾動。

+0

事實上,我在Extjs中創建了橫向滾動的看板。當任務列表很大時,我們需要滾動查看該列表。有很多任務,我們可以將任何列表的任務拖到另一個不可見的列表中。 –

+0

@AjayThakur我試圖谷歌爲什麼Dropzone沒有註冊滾動後,我發現一些信息,當在Ext.view中使用區域時可能有問題*,並共享相同的元素。將它重寫到具有zone + view或類似內容的容器可能是值得的。 – pagep