|
<ejs-grid #normalgrid [dataSource]='data' ... >
<e-columns>
.
.
<e-column field='ShipCountry' headerText='Ship Country' width='150' editType='dropdownedit' [edit]='editparams' [validationRules]='shipcountryrules'></e-column>
</e-columns>
</ejs-grid> |
|
export class AppComponent {
public shipcountryrules: Object;
public ngOnInit(): void {
this.shipcountryrules = { required: [true, 'Required'] };
}
} |
|
// Grid’s click event function
onClickFun(e) {
setTimeout(
function (e) {
// Check if Grid is in edit state and if the dropdown column is validated
if (this.grid.isEdit && this.grid.editModule.formObj.validated.indexOf("ShipCountry") != -1) {
// Dropdown instance is accessed by using it class to retrieve the dropdown element in the edit form
var dropObj = this.grid.editModule.formObj.element.querySelector(".e-dropdownlist").ej2_instances[0];
if (isNullOrUndefined(dropObj.value)) {
// Adding this class highlights dropdown border
// You can also use your own custom class here
dropObj.element.parentElement.classList.add("e-error");
} else {
// Class is removed if dropdown has value
dropObj.element.parentElement.classList.remove("e-error");
}
}
}.bind(this), 10);
} |
|
<ejs-grid (click)='onClickFun($event)' ...>
<e-columns>
<e-column field='ShipCountry' [validationRules]='shipcountryrules' [edit]='editparams' editType='dropdownedit'></e-column>
</e-columns>
</ejs-grid> |
|
public ngOnInit(): void {
this.shipcountryrules = { required: [true, "Required"] };
this.editparams = { params: { popupHeight: "300px", blur: this.onBlur.bind(this) } };
}
// Edit dropdown’s blur event function
onBlur() {
// Dropdown instance is accessed by using it class to retrieve the dropdown element in the edit form
// If there are multiple edit dropdown’s in the form this actions needs to be performed for each of them
var dropObj = this.grid.editModule.formObj.element.querySelector(".e-dropdownlist").ej2_instances[0];
if (isNullOrUndefined(dropObj.value)) {
// Adding this class highlights dropdown border
// You can also use your own custom class here
dropObj.element.parentElement.classList.add("e-error");
} else {
// Class is removed if dropdown has value
dropObj.element.parentElement.classList.remove("e-error");
}
} |
|
this.dpParams = {
create: () => {
.
.
}
.
.
write: (args: { rowData: object; column: Column }) => {
dropDownObj = new DropDownList({
.
.
blur: function (e) {
if (isNullOrUndefined(this.dropDownObj.value)) {
this.dropDownObj.element.parentElement.classList.add('e-error')
}
else {
this.dropDownObj.element.parentElement.classList.remove('e-error')
}
}.bind(this),
});
dropDownObj.appendTo(this.elem);
}
}; |
|
// Grid’s click event function
onClickFun(e){
setTimeout(function (e) {
// Check if Grid is in edit state and validation has been performed
if (this.grid.isEdit && this.grid.editModule.formObj.validated.length !== 0) {
this.grid.editModule.formObj.inputElements.forEach(ele => {
// Get the available dropdown list controls from the edit form elements
if (ele.classList.contains('e-dropdownlist')) {
// Dropdown instance
var dropInst = ele.ej2_instances[0];
// The error class is added/removed based on the dropdown value
if (isNullOrUndefined(dropInst.value)) {
ele.parentElement.classList.add('e-error');
} else {
ele.parentElement.classList.remove('e-error');
}
}
})
}
}.bind(this), 10)
} |