I am having a play around with the grid. I have implemented the following example where batch update/create/delete from this post kendo-grid-batch-incell-save-changes-with-single-trigger-for-create-update-destroy. This works nicely where I get the rows being created/updated/deleted.
However, if I need to do some custom server side validation in a save event before the changes are committed - if there are any errors, is it possible to return the errors and set them back in the grid supposing my save send handler is:
function
sendSaveAllData() {
var
grid = $(
'#mygrid'
).data(
"kendoGrid"
);
var
finalData = ...;
// send the data with one request to the server
$.ajax({
url:
"@Url.Action("
SaveAllBatchChanges
", "
MyController
")"
,
data: finalData,
type:
"POST"
,
error:
function
() {
//Handle the server errors
},
success:
function
(data) {
//alert("update on server is completed");
showMessage(
'success'
,
'My Batch'
,
'Successfully saved batch changes.'
)
//refresh the grid
grid.dataSource._destroyed = [];
grid.dataSource.read();
}
})
}
With controller method:
public
ActionResult SaveAllBatchChanges(
[Bind(Prefix =
"updated"
)]List<BatchEditModel> updated,
[Bind(Prefix =
"new"
)]List<BatchEditModel> created,
[Bind(Prefix =
"deleted"
)]List<BatchEditModel> destroyed)
{
// do some validation before notifying server
// save if valid
return
Json(
"Success!"
);
}
At the minute I show a popup message to the user which reads success - but I haven't got any code in place currently to do the validate until I find something concrete to put in place.
Ideally I want to set cell style of errors in the grid if possible back in the browser - ie red background colour if the cell contains an error.
Is there a way to manually set error messages in the grid (client side) and highlight the error cells from an external ajax post?
Thanks
Andez