We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Not working drag and drop by group on the Grid

Drag and Drop function doesn't work on the DataGrid that made by Group.
It works in a regular Grid well, but if I group the grid, it doesn't work.
Help me..

3 Replies

PS Pavithra Subramaniyam Syncfusion Team February 21, 2019 12:27 PM UTC

Hi Michal,  
Greetings from Syncfusion,  
We have validated your query and the support for row drag and drop with Grouping is not feasible in the Essential JavaScript 2 Grid. So We have prepared a workaround sample based on the Grouping with Row drag and drop support. you can achieve that requirement by using rowDrop event and you can update the grid data source based on the row dragging to grouped column. Please refer to the below code example, documentation link and sample link for more information.  
let grid: Grid = new Grid(  
            dataSource: orderDetails,  
            allowRowDragAndDrop: true,  
            selectionSettings: { type: 'Multiple' },  
            columns: [  
                . . . .  
function rowDrop(arg){    
  let gObj: any = (<any>document.getElementById('Grid')).ej2_instances[0];  
  let startedRow:any = arg.rows[0];  
  let targetRow:any = arg.target.closest('tr');    
  if(targetRow.classList.contains('e-row') && targetRow.classList.length ){  
     targetRow = targetRow;  
  } else{  
    targetRow = arg.target.closest('tr').nextSibling;  
  let startRowIndex: number = parseInt(startedRow.getAttribute("aria-rowindex"),10);  
  let targetRowIndex: number = parseInt(targetRow.getAttribute("aria-rowindex"),10);  
  if(startRowIndex === targetRowIndex){  
  let groupedCol:any = (gObj as any).groupSettings.columns;  
  for(let i:number=0,len:number=groupedCol.length;i< len; i++){  
  let dataIndex: number = this.dataSource.indexOf(arg.data);  
  let value: any = this.currentViewData["records"][targetRowIndex][groupedCol[i]];//update the group column value to dragging row data  
  this.currentViewData["records"][startRowIndex][groupedCol[i]] = value;     
  arg.cancel =true;  // prevent default action of rowDrop event   
Please get back to us, if you need further assistance.  
Pavithra S.   

ST Stefan Tmusic February 21, 2019 12:34 PM UTC


But it doesn't work within the same group.

PS Pavithra Subramaniyam Syncfusion Team February 22, 2019 10:13 AM UTC

Hi Michal, 
Greetings from the Syncfusion, 
As per your query, we have modified the sample to row drag and drop within the same group also. In below sample, you can achieve the drag and drop in the same group in the Essential JavaScript 2 Grid UI end otherwise the EJ2 Grid data source as update based on row drag and drop on the grouped rows. 
  let grid: Grid = new Grid( 
            .   .    .    . 
            .   .   .   .  
function rowDrop(arg) {   
  let gObj: any = (<any>document.getElementById('Grid')).ej2_instances[0]; 
  if ((gObj as any).groupSettings.columns.length > 0) { 
    .   .   .   . 
    for (let i: number = 0, len: number = groupedCol.length; i < len; i++) { 
      let dataIndex: number = this.dataSource.indexOf(arg.data); 
      let value: any = this.currentViewData["records"][targetRowIndex][groupedCol[i]]; 
      let dragStartColData: any = this.currentViewData["records"][startRowIndex][groupedCol[i]]; 
      if (dragStartColData === value) {         
        let dragRow: any = [].slice.call(this.getContentTable().querySelectorAll('tbody .e-row')).filter(item => item.getAttribute("data-uid") == startedRow.getAttribute("data-uid")); 
        let cloneRow: any = dragRow[0].cloneNode(true); 
        gObj.getContentTable().querySelector('tbody').insertBefore(cloneRow, targetRow); 
        let dragborderEle:any = cloneRow.querySelector('.e-dragborder'); 
        if (dragborderEle) { 
Please get back to us, you need further assistance. 
Pavithra S.  

Live Chat Icon For mobile
Up arrow icon