ParamQuery grid support forum
General Category => ParamQuery Pro Evaluation Support => Topic started by: cmcooper on September 17, 2016, 12:54:23 am
-
I'm trying to implement saving of nested grids when the parent grid is saved. The parent row has an identity column that is generated by the db. This column is also a foreign key in the nested grid rows, so I need the value before saving the nested grid. At what point after calling commit() on the parent grid will the identity be populated in the parent row?
function saveChanges(){
//attempt to save editing cell.
if (grid.saveEditCell() === false) {
return false;
}
if (grid.isDirty() && grid.isValidChange({ focusInvalid: true }).valid) {
var changes = grid.getChanges({ format: 'byVal' });
// Save changes to db
$.ajax({
dataType: "json",
type: "POST",
async: false,
beforeSend: function (jqXHR, settings) {
grid.showLoading();
},
url: "SaveChanges",
data: { strChanges: JSON.stringify(changes) },
success: function (changes) {
grid.commit({ type: 'add', rows: changes.addList });
grid.commit({ type: 'update', rows: changes.updateList });
grid.commit({ type: 'delete', rows: changes.deleteList });
grid.history({ method: 'reset' });
},
complete: function () {
grid.hideLoading();
}
});
}
}
-
commit() is a synchronous method, so id of the parent row is populated just after call to commit() method.
-
After the calls to commit() above, pdata still does not have the ID populated for new rows. Additionally, I have a saveChanges method on the detail grid.
saveChanges: function (thisGrid) {
DoSomething(rowData.ID, thisGrid);
},
When this is called after the call to commit() on the parent grid, rowData.ID is still undefined for new rows.
-
You need to check the value of id in changes.addList in the success callback. If it's not there, you need to correct remote script to add id of new rows.
success: function (changes) {
//check whether changes.addList contain id of rows.
grid.commit({ type: 'add', rows: changes.addList });
grid.commit({ type: 'update', rows: changes.updateList });
grid.commit({ type: 'delete', rows: changes.deleteList });
grid.history({ method: 'reset' });
},
-
There were actually two issues here.
1. I changed
return js.Serialize(dlist);
to
return JsonConvert.SerializeObject(dlist, new Newtonsoft.Json.Converters.IsoDateTimeConverter() { DateTimeFormat = "MM/dd/yyyy" });
in the SaveChanges() method in the controller.
2. I had to hide the detail column while committing.