Hi team,
I am trying to set a value coming from controller after to add a record, but the fields don't update, I am doing it this way:
I am using EJS controls.
Thanks,
|
var flag = false;
// Grid’s actionBegin event handler
function actionBegin(e) {
// Initially flag needs to be false in order to enter this condition
if (!flag) {
// Check condition if event is triggered for save action
if (e.requestType == "save") {
// Current added/edited row data
var editedData = e.data;
// The default save operation is cancelled and edit closed
e.cancel = true;
this.closeEdit();
// Here you can send the data to your server
var ajax = new Ajax({
type: "GET",
contentType: "application/json; charset=utf-8",
data: JSON.stringify([editedData])
});
ajax.onSuccess = data => {
// Updated data retrieved from server
var data = JSON.parse(data);
// Flag variable is enabled to skip execution of the above code when grid ends add/edit
flag = true;
var gridObj = document.getElementById('Grid').ej2_instances[0];
if (e.action == 'edit') {
// Condition executes for edit action
// Row index to be updated is retrieved using its primary key value
// Please ensure the primary key value is not modified for edited data
var rowIndex = gridObj.getRowIndexByPrimaryKey(data["OrderID"]);
// Modified edited data is updated to the Grid
gridObj.updateRow(rowIndex, data);
} else {
// Condition executes for add action
// Modified added data will be added to the Grid
gridObj.addRecord(data);
}
}
ajax.send();
}
}
}
// Grid’s actionComplete event handler
// Triggers after an action is successfully completed in the Grid
function actionComplete(e) {
if (e.requestType === "save") {
// The global flag variable is disabled after operation is successfully performed so that it can enter the condition on next execution
flag = false;
}
} |
Hi
Sujith,
Thank for your help, I tried your code but doesn't work could you share some complete example?
Thanks,