|
[App.component.html]
<div class="control-section">
<ejs-grid [dataSource]='data' #grid allowPaging='true' [pageSettings]='pageSettings' [editSettings]='editSettings' [toolbar]='toolbar'>
<e-columns>
<e-column field='OrderID' headerText='Order ID' width='120' textAlign='Right' isPrimaryKey='true' [validationRules]='orderidrules'></e-column>
<e-column field='Customer' width='150' editType='dropdownedit' [validationRules]='Customerrules' [edit]='editparams'></e-column>
<e-column field='EmployeeID' headerText='Employee ID' width='120' [validationRules]='idrules'></e-column>
</e-columns>
</ejs-grid>
</div>
|
|
[App.component.ts]
@Component({
selector: 'app-root',
templateUrl: 'app.component.html',
providers: [ToolbarService, EditService, PageService]
})
export class AppComponent {
@ViewChild('grid', {static: true})
public grid: GridComponent;
public ngOnInit(): void {
this.data = [
{
OrderID: 10248, EmployeeID: 5, Customer: 'TOM'
},
{
OrderID: 10249, EmployeeID: 6, Customer: 'VINET'
},
{
OrderID: 10250,EmployeeID: 2, Customer: 'TOMSP'
}];
this.editSettings = { allowEditing: true, allowAdding: true, allowDeleting: true };
this.toolbar = ['Add', 'Edit', 'Delete','Update'];
this.orderidrules = { required: true, number: true };
this.idrules = { required: false,custom:[this.validateID, 'Enter a value more than 0'] };
this.Customerrules = { required: false,custom:[this.validateCustomer, 'Enter a value with 4 or more characters']};
this.editparams = { params: { change: this.dropDownChange.bind(this), popupHeight: '300px' }};
}
validateID (e) {
return parseInt(e.value) > 0;
}
validateCustomer (e) {
return e.value.length > 4;
}
dropDownChange (e) {
// here we invoking the form validation on value change
this.grid.editModule.formObj.validate();
}
} |