拖放和具有角2

问题描述:

重新排序AG-网格中的行。在gridOptions拖放和具有角2

 processRowPostCreate: (params) => { 
       this.generateRowEvents(params); 
      }, 

它调用

private generateRowEvents(params) { 
     params.eRow.draggable = true; 
     params.eRow.ondragstart = this.onDrag(event); 
     params.eRow.ondragover = this.onDragOver(event); 
     params.eRow.ondrop = this.onDrop(event); 
    } 

我跟踪源recrord在ondrag当方法

     var targetRowId: any = $event.target.attributes.row.value; 
        this.savedDragSourceData = targetRowId; 

onDragOver像往常一样

private onDrop($event) { 
     if ($event && !this.infiniteLoopCheck) { 
      if ($event.dataTransfer) { 
       if (this.enableInternalDragDrop) { 
        this.infiniteLoopCheck= true; 

         var draggedRows: any = this.gridRows[this.savedDragSourceData]; 

        // get the destination row 
        var targetRowId: any = $event.target.offsetParent.attributes.row.value; 

        // remove from the current location 
        this.gridOptions.api.removeItems(this.gridOptions.api.getSelectedNodes()); 

        // remove from source Data 
        this.gridRows.splice(this.savedDragSourceData, 1); 


        if (draggedRows) { 
         // insert into specified drop location 
         this.gridOptions.api.insertItemsAtIndex(targetRowId, [draggedRows]); 

         // re-add rows to source data.. 
         this.gridRows.splice(targetRowId, 0, checkAdd); 

         this.saveRequestEvent.emit(this.gridRows);// shout out that a save is needed      } 
        this.v= false; 
       } 
       else { 
        this.onDropEvent.emit($event); 
       } 
      } 
     } 
    } 

我的网格选项:

commonGridOptions: any = { 
     enableColResize: true, 
     enableSorting: false, 
     enableFilter: false, 
     groupHeaders: true, 
     rowHeight: this.gridRowHeight, 
     suppressRowSelection: false, 
     rowSelection: 'single', 
     suppressCellSelection: true, 
     suppressRowClickSelection: true, 
     DragAndDrop:false, 
} 

我试图达到的阻力,并通过使用上面的代码拖放功能: 但是当我尝试获得源行索引,同时起拖($ event.target .attributes.row.value)我无法获取$ event.target.attributes中的行。

而且我无法获得目标行索引($ event.target.offsetParent.attributes.row.value)。

请帮我解决这个问题。

这是非常可观的,如果提供蹲下的例子。

我能够根据拖放功能做记录。这是我的代码。当按列排序的网格(由于排序,拖放不会有任何视觉效果)时,我跳过了修改。

processRowPostCreate: (params) => { 
     params.eRow.draggable = true; 
     params.eRow.ondragstart = (event: DragEvent) => { 
      this._newRowIndex = params.rowIndex; 
      this._currentRowIndex = params.rowIndex; 
     }; 
     params.eRow.ondragenter = (event: DragEvent) => { 
      this._newRowIndex = params.rowIndex; 
     }; 
     params.eRow.ondragend = (event: DragEvent) => { 
      let sortmodel = this.gridOptions.api.getSortModel(); 
      if (sortmodel.length === 0 && this._newRowIndex !== this._currentRowIndex) { 
       let record = params.node.data; 
       this.handleRearrangement(); 
       this.records.splice(this._newRowIndex, 0, this.records.splice(this._currentRowIndex, 1)[0]); 
       this.gridOptions.api.removeItems([params.node], false); 
       this.gridOptions.api.insertItemsAtIndex(this._newRowIndex, [record], false); 
      } else { 
       this._newRowIndex = this._currentRowIndex; // just to be sure 
      } 

     }; 
    }