Hi Team,
Our requirement is to show validation when user enters invalid date format/value in editable grid and not turn the cell to blank. Currently grid date picker seems to be validating data and returns null when value is invalid.
Example :
[app.component.html]
<ejs-grid #grid id="grid" [dataSource]='data' allowPaging='true' [editSettings]='editSettings' [toolbar]='toolbar'>
<e-columns>
<e-column field='OrderID' headerText='Order ID' width='120' textAlign='Right' isPrimaryKey='true'
[validationRules]='orderidrules' editType='numericedit'></e-column>
<e-column field='OrderDate' headerText='Order Date' [validationRules]='Orderdaterules' width='130'
format='yMd' [edit]='dpParams1'></e-column>
<e-column field='CustomerID' headerText='Customer Name' width='120'>
</e-column>
</e-columns>
</ejs-grid>
[app.component.ts]
export class AppComponent {
@ViewChild('grid', { static: true })
public grid: GridComponent;
----
public Orderdaterules: Object;
public elem1: HTMLElement;
public datePickerObj1: DatePicker;
public dpParams1: IEditCell;
public ngOnInit(): void {
----
this.Orderdaterules = {
required: true,
date: true, // date validation
min: [
this.OrderdatecustomFn,
'enter the datevalue greater than today time'
] // custom validation
};
this.dpParams1 = {
create: () => {
this.elem1 = document.createElement('input');
return this.elem1;
},
read: () => {
return this.datePickerObj1.value;
},
destroy: () => {
this.datePickerObj1.destroy();
},
write: (args: { rowData: object; column: Column }) => {
this.datePickerObj1 = new DatePicker({
value: args.rowData[args.column.field],
floatLabelType: 'Never'
});
this.datePickerObj1.appendTo(this.elem1);
}
};
}
public OrderdatecustomFn: (args: {[key: string]: string; }) => boolean = (args: { [key: string]: string }) => {
// validate the date as you want
return this.datePickerObj1.value > new Date();
};
}
|