[app.component.ts]
actionComplete(args: DialogEditEventArgs): void {
if (args.requestType === "beginEdit" || args.requestType === "add") {
// Set initial Focus
if (args.requestType === "beginEdit") {
var proxy = this;
proxy["event"] = event;
setTimeout(
function(e) {
var target = this.event.target;
if (target.classList.contains("e-rowcell")) {
var colIndex = Number(target.getAttribute("aria-colindex"));
var field = this.grid.getColumnByIndex(colIndex).field;
var formEle = this.grid.editModule.formObj.element;
var inputEle = formEle.querySelector("[name=" + field + "]");
var component = inputEle
.closest(".e-rowcell")
.querySelector(".e-control");
if (component) {
component.ej2_instances[0].focusIn();
} else {
inputEle.focus();
}
console.log(inputEle);
}
}.bind(proxy),
100
);
} else if (args.requestType === "add") {
setTimeout(
function(e) {
var formEle = this.grid.editModule.formObj.element;
formEle
.querySelector("[name='OrderID']")
.ej2_instances[0].focusIn();
}.bind(this),
100
);
}
}
} |
[app.component.ts]
Public flag:Boolean=true;
actionBegin(args) {
if (args.requestType === "save" && this.flag ) {
args.cancel=true;
// Here you can call the server side validation
//Once done the server validation, you need to save the edited record programmatically using endEdit method as given below
this.flag=false;
this.grid.endEdit()
}
}
actionComplete(args){
if(args.requestType == “save” && !this.flag){
this.flag=true;
}
} |
[app.component.ts]
toolbarClick(e) {
switch (e.item.id) {
case "toolbar_add":
this.isCustomadd = true;
let row: any = {
OrderID: 101, // You should add PrimaryKey column value then only we can perform CRUD action properly
CustomerName: "Default",
Freight: 0,
OrderDate: new Date().toString(),
ShipCountry: "Default"
};
this.grid.addRecord(row, this.grid.pageSettings.pageSize - 1);
}
}
actionComplete(args: DialogEditEventArgs): void {
. . . .
if (args.requestType == "save" && this.isCustomadd) {
this.isCustomadd = false;
this.grid.selectRow(this.grid.pageSettings.pageSize - 1); // select the clicked row by using the rowIndex
this.grid.editModule.startEdit(); // Call the startEdit method to edit the selected row
}
} |