I ran into issue, where i do not know how to implement my own
custom validations for grid fields.
I need to connect to database to check if value exist then return
validation error
thanks
After filling in one of the fields in grid, the database is connected to make sure that the same number is not used in advance and display a validation error message to the user if the number is already used validation start when focused out current cell.the connection to database will be after the user leave the field and the validation error message will be show if the number in the field is used before
|
<ejs-grid #grid [dataSource]='data' [editSettings]='editSettings'
(actionComplete)="actionComplete($event)"[toolbar]='toolbar' [allowPaging]='true'>
<e-columns>
<e-column field='OrderID' headerText='Order ID' isPrimaryKey='true' width=120></e-column>
<e-column field='EmployeeID' headerText='Employee ID' [validationRules]='employeeIDRules' width=150></e-column>
. . . . .
<e-column field='ShipCountry' headerText='Ship Country' width=150></e-column>
</e-columns>
</ejs-grid> |
|
export class FetchDataComponent {
public actionComplete(args: any) {
if (args.requestType === 'beginEdit') {
args.row.querySelector('form').ej2_instances[0].validationComplete = (e) => {
if (e.inputName == "EmployeeID") {
if(!this.flag && e.errorElement) {
e.errorElement.innerHTML = 'Please enter valid number'
this.flag = true;
}
}
}
}
}
ngOnInit(): void {
this.toolbar = ['Add', 'Edit', 'Update', 'Cancel'];
this.employeeIDRules = { required: true, minLength: [this.customFn, 'Checking...'] };
. . . .
}
public customFn: (args: { [key: string]: string }) => (void) = (args: { [key: string]: string }) => {
let finalvalue = parseInt(args['value'], 10);
let ajax = new Ajax("/Home/getStatus", "POST", true); // call API
ajax.send(JSON.stringify({ EmployeeID : finalvalue })).then( //
(value) => {
if (<any>value === "true") { // check the status
this.final = true;
} else {
this.final = false;
this.flag = false;
}
});
return this.final;
};
}
|
|
let ajax = new Ajax("/Home/getStatus", "POST", true); // call API
ajax.beforeSend = function (args: any) {
this.httpRequest.setRequestHeader('header', 'true');
} |
|
<ejs-grid #grid [dataSource]='data' [editSettings]='editSettings'
(actionComplete)="actionComplete($event)"[toolbar]='toolbar' [allowPaging]='true'>
<e-columns>
<e-column field='OrderID' headerText='Order ID' isPrimaryKey='true' width=120></e-column>
<e-column field='EmployeeID' headerText='Employee ID' [validationRules]='employeeIDRules' width=150></e-column>
<e-column field='CustomerID' headerText='Customer ID' width=150></e-column>
<e-column field='Freight' headerText='Freight' editType="numericedit" format="C2" width=150></e-column>
<e-column field='ShipCountry' headerText='Ship Country' width=150></e-column>
</e-columns>
</ejs-grid>
|