Results 1 to 2 of 2

Thread: Grid CellSelectionModel and Drag & Drop - a workaround

  1. #1
    Sencha User Izhaki's Avatar
    Join Date
    Apr 2009
    Location
    London
    Posts
    118

    Default Grid CellSelectionModel and Drag & Drop - a workaround

    A few people on this forum has complained about GridPanel not supporting Drag and Drop with CellSelectionModel. For some reason, the current 3.0 code assumes that GridPanel will only work with RowSelectionModel.

    I would assume that this fix would have at some stage to be merge with the current code:



    Code:
    Ext.override(Ext.grid.GridPanel, {
        getDragDropText : function(){
          var count;
          
          var sm = this.selModel;
          
          if (sm instanceof Ext.grid.RowSelectionModel)    
            count = sm.getCount();
          if (sm instanceof Ext.grid.CellSelectionModel)
            count = 1;
          return String.format(this.ddText, count, count == 1 ? '' : 's');
        },
    });
    
    Ext.override(Ext.grid.GridDragZone, {
    
        getDragData : function(e){
            var t = Ext.lib.Event.getTarget(e);
            var rowIndex = this.view.findRowIndex(t);
            var cellIndex = this.view.findCellIndex(t);
            
            if(rowIndex !== false){
                var sm = this.grid.selModel;
                
                // RowSelectionModel
                if (sm instanceof Ext.grid.RowSelectionModel)
                {
                  if(!sm.isSelected(rowIndex) || e.hasModifier()){
                      sm.handleMouseDown(this.grid, rowIndex, e);
                  }
                  return {grid: this.grid, ddel: this.ddel, rowIndex: rowIndex, selections:sm.getSelections()};            
                }
                
                // CellSelectionModel
                if (sm instanceof Ext.grid.CellSelectionModel)
                {
                  sel = sm.getSelectedCell();
                  
                  rowAlreadySelected = sel && sel[0] == rowIndex;
    
                  if(!rowAlreadySelected || e.hasModifier()){
                      sm.handleMouseDown(this.grid, rowIndex, cellIndex, e);
                  }
                  
                  store = this.grid.getStore();
                  sel = sm.getSelectedCell();
                  if (sel)
                    return {grid: this.grid, ddel: this.ddel, rowIndex: rowIndex, selections: [store.getAt(sel[0])]};
                  else 
                    return {grid: this.grid, ddel: this.ddel, rowIndex: rowIndex, selections: []};              
                }            
            }
            return false;
        },
    
    });
    Last edited by sven; 17 Aug 2009 at 3:31 AM. Reason: moved to extjs3 help forum from GXT forums

  2. #2

    Default Works Great

    This works great for me. Thanks for sharing.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •