Drop and Drag Columns in ejs grid

HI
I am using ejs grid . please send code for column drop and drag.


3 Replies 1 reply marked as answer

MS Manivel Sellamuthu Syncfusion Team September 25, 2020 08:23 AM UTC

Hi Narsimsetty, 

Greetings from Syncfusion support. 

To enable reordering we suggest you to define allowReordering to true. To use reordering feature we need to inject ReorderService in the provider section of AppModule.  

Please refer the below code example and documentation and demo for more information. 

<div class="control-section"> 
    <ejs-grid [dataSource]='data' allowReordering='true'> 
        <e-columns> 
            <e-column field='EmployeeID' headerText='Employee ID' width='120' textAlign='Right'></e-column> 
            <e-column field='FirstName' headerText='Name' width='140'></e-column> 
            <e-column field='Title' headerText='Title' width='170'></e-column> 
            <e-column field='HireDate' headerText='Hired Date' width='120' format='yMd' textAlign='Right'></e-column> 
            <e-column field='ReportsTo' headerText='Reports To' width='120' textAlign='Right'></e-column> 
        </e-columns> 
    </ejs-grid> 
</div> 
import { Component, OnInit } from '@angular/core'; 
import { employeeData } from './data'; 
import { ReorderService } from '@syncfusion/ej2-angular-grids'; 
 
@Component({ 
    selector: 'ej-gridreorder', 
    templateUrl: 'reorder.html', 
    providers: [ReorderService] 
}) 
export class ReorderComponent implements OnInit { 
    public data: Object[]; 
 
    ngOnInit(): void { 
        this.data = employeeData; 
    } 
} 



Please let us know, if you need further assistance. 

Regards, 
Manivel 



NC Narsimsetty Chalamaiah September 28, 2020 11:54 AM UTC

Hi

We have seen below code .
but we need to save columns into db, when i do drag and drop columns.

please share code .


MS Manivel Sellamuthu Syncfusion Team September 29, 2020 05:24 PM UTC

Hi Narsimsetty, 
 
Query : we need to save columns into db, when i do drag and drop columns. 
 
We have validated your requirement and you can the get the new column ordered after reordered the column by using ‘actionComplete’ event and its requestType as ‘reorder’ .  Please find the code example and sample for your reference. 
 
[app.component.html] 
    <ejs-grid #grid [dataSource]='data' allowReordering='true' (actionComplete)="actionComplete($event)" > 
        <e-columns> 
            <e-column field='EmployeeID' headerText='Employee ID' width='120' textAlign='Right'></e-column> 
            <e-column field='FirstName' headerText='Name' width='140'></e-column> 
            <e-column field='Title' headerText='Title' width='170'></e-column> 
            <e-column field='HireDate' headerText='Hired Date' width='120' format='yMd' textAlign='Right'></e-column> 
            <e-column field='ReportsTo' headerText='Reports To' width='120' textAlign='Right'></e-column> 
        </e-columns> 
    </ejs-grid> 
 
[app.component.ts] 
 
 
export class AppComponent { 
    public data: Object[]; 
    @ViewChild('grid') 
    public grid: GridComponent; 
 
     
actionComplete(args){ 
 
  if(args.requestType == 'reorder'){ 
    let colName = []; 
 
    for(let i=0; i< this.grid.columns.length; i++){ 
      colName.push((this.grid.columns[i] as Column).field); 
    } 
    console.log(colName); //  you can update column order in your dB 
 
  } 
} 
 
    ngOnInit(): void { 
        this.data = employeeData; 
    } 
} 
 
In the above sample, we can get the new column order by using actionComplete event . You have send the request to server and update the new column order in your database through the above actionComplete events (and it requestType as ‘reorder’) 
 
 
 
 
Regards, 
Manivel 


Marked as answer
Loader.
Up arrow icon