The Grid Row drag and drop allows you to drag grid rows and drop to another Grid or custom component.
To enable Row drag and drop in the Grid, set the allowRowDragAndDrop
to true.
The target component on which the Grid rows to be dropped can be set by using
targetID
.
To use Row Drag and Drop, you need to inject RowDDService in the provider section of AppModule.
import { Component, OnInit } from '@angular/core';
import { data } from './datasource';
import { RowDropSettingsModel, SelectionSettingsModel } from '@syncfusion/ej2-angular-grids';
@Component({
selector: 'app-root',
template: `<ejs-grid id='Grid' [dataSource]='data' [allowRowDragAndDrop]='true'
[rowDropSettings]='rowDropOptions' [selectionSettings]='selectionOptions'>
<e-columns>
<e-column field='OrderID' headerText='Order ID' textAlign='Right' width=120></e-column>
<e-column field='CustomerID' headerText='Customer ID' width=150></e-column>
<e-column field='ShipCity' headerText='Ship City' width=150></e-column>
<e-column field='ShipName' headerText='Ship Name' width=150></e-column>
</e-columns>
</ejs-grid>
<ejs-grid id='DestGrid' [dataSource]='destGridData' [allowRowDragAndDrop]='true'
[rowDropSettings]='destRowDropOptions' [selectionSettings]='selectionOptions'>
<e-columns>
<e-column field='OrderID' headerText='Order ID' textAlign='Right' width=120></e-column>
<e-column field='CustomerID' headerText='Customer ID' width=150></e-column>
<e-column field='ShipCity' headerText='Ship City' width=150></e-column>
<e-column field='ShipName' headerText='Ship Name' width=150></e-column>
</e-columns>
</ejs-grid>`,
styleUrls: ['./app/app.style.css']
})
export class AppComponent implements OnInit {
public data: object[];
public destGridData: object[];
public rowDropOptions: RowDropSettingsModel;
public destRowDropOptions: RowDropSettingsModel;
public selectionOptions: SelectionSettingsModel;
ngOnInit(): void {
this.data = data.slice(0, 5);
this.destGridData = [];
this.rowDropOptions = { targetID: 'DestGrid' };
this.destRowDropOptions = { targetID: 'Grid' };
this.selectionOptions = { type: 'Multiple' };
}
}
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { GridModule, PageService, SelectionService, RowDDService } from '@syncfusion/ej2-angular-grids';
import { AppComponent } from './app.component';
/**
* Module
*/
@NgModule({
imports: [
BrowserModule,
GridModule
],
declarations: [AppComponent],
bootstrap: [AppComponent],
providers: [PageService, SelectionService, RowDDService]
})
export class AppModule { }
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { enableProdMode } from '@angular/core';
import { AppModule } from './app.module';
enableProdMode();
platformBrowserDynamic().bootstrapModule(AppModule);
- Selection feature must be enabled for row drag and drop.
- Multiple rows can be selected by clicking and dragging inside the grid. For multiple row selection, the
type
property must be set to Multiple.