Category / Section
How to enable inline editing in Angular 4 Data Grid/Table?
2 mins read
The Essential JS 2 Angular 4 Data Grid supports the following edit modes to perform CRUD ( Create, Read, Update and Delete) actions through an interactive UI with simple configuration.
- Inline
- Dialog
- Batch
- Inline/Dialog Template
In this knowledge base, we are going to explain about, how to enable inline editing in Syncfusion Angular 4 Data Grid.
- Grid Editing feature requires EditService and ToolbarService for performing edit actions so we need to define this services in app.module.ts file.
import { EditService,ToolbarService } from '@syncfusion/ej2-angular-grids'; @NgModule({ declarations: [ AppComponent ], imports: [ BrowserModule, GridModule ], providers: [EditService, ToolbarService], bootstrap: [AppComponent] }) export class AppModule { }
- To perform editing in Angular 4 data grid its requires to set a isPrimaryKey property of column as true for the unique column in the data source since the CRUD actions performed based on this unique column.
<ejs-grid [dataSource]='data' [editSettings]='editSettings' [toolbar]='toolbar' height='315px'> <e-columns> <e-column field='OrderID' headerText='Order ID' textAlign='Right' isPrimaryKey='true' width=100></e-column> <e-column field='CustomerID' headerText='Customer ID' width=120></e-column> <e-column field='Freight' headerText='Freight' textAlign='Right' width=120 format='C2'></e-column> <e-column field='ShipCountry' headerText='Ship Country' width=150></e-column> </e-columns> </ejs-grid>
- To perform CRUD actions using Inline edit mode, it requires to set mode property of editSettings as “Normal” and also need to set allowAdding, allowEditing and allowDeleting property of editSettings as “true” . Define the toolbar items in the toolbar property of data grid.
<ejs-grid [dataSource]='data' [editSettings]='editSettings' [toolbar]='toolbar' height='315px'> <e-columns> <e-column field='OrderID' headerText='Order ID' textAlign='Right' isPrimaryKey='true' width=100></e-column> <e-column field='CustomerID' headerText='Customer ID' width=120></e-column> <e-column field='Freight' headerText='Freight' textAlign='Right' width=120 format='C2'></e-column> <e-column field='ShipCountry' headerText='Ship Country' width=150></e-column> </e-columns> </ejs-grid> import { Component, OnInit } from '@angular/core'; import { EditSettingsModel, ToolbarItems } from '@syncfusion/ej2-angular-grids'; @Component({ selector: 'app-root', templateUrl: './app.component.html', styleUrls: ['./app.component.css'] }) export class AppComponent implements OnInit { public data: Object[]; public editSettings: EditSettingsModel; public toolbar: ToolbarItems[]; ngOnInit() { this.editSettings = { allowEditing: true, allowAdding: true, allowDeleting: true, mode:"Normal" }; this.toolbar = ['Add', 'Edit', 'Delete', 'Update', 'Cancel']; } }
Summary
In this GitHub repository, the application prepared from the above steps has been committed, and it is readily runnable. If you have any queries or require clarifications. Please let us know in comments below. You can also contact us through our Support forum or Direct-Trac. We are happy to assist you!