I have a kendo grid that I am adding a new item to (POST), there is a chance for a 409 error (duplicate item), how can i handle this? I NEED to use grid.saveChanges(), it's a requirement. The code below works, I just need to handle errors with it.
(I replaced the actual values with "values")
var dataSource = grid.dataSource;
dataSource.add( {
Values: data.values
});
grid.saveChanges();
here is some code that I use for handling save errors for a grid
//This works with post 2014 Kendo Update.
function NewError_Handler(e)
{
if(e.errors)
{
$(".k-grid").each(function () {
var grid = $(this).data("kendoGrid");
if (grid !== null && grid.dataSource == e.sender) {
// We have a winner!
grid.one("dataBinding", function (e) {
e.preventDefault();
});
var message = "";
$.each(e.errors, function (key, value) {
if ('errors' in value) {
$.each(value.errors, function () {
message += this + "<br/>";
});
}
});
$('#errorWindow').removeClass('hidden');
$('#errors').text("");
$('#errors').append(message);
}
});
}
}
this then applies the errors this piece of html (loaded as a partial view for me MVC)
<div id="errorWindow" class="panel panel-danger hidden ">
<div class="panel-heading">Errors Found </div>
<div class="panel-body panel-danger">
<div id="errors">
</div>
</div>
</div>
this is called via the Error event handler within the datasource setup.
This link should help with you setting it up http://docs.telerik.com/kendo-ui/api/framework/datasource#events-error
(I generally use the MVC wrappers for my kendo needs)
Hope this helps.
dataSource: z.dataSource({
transport: {
create: {
url: "/url/url",
type: "POST",
complete: function (e) {
if (e.status == 409) {
// Duplicate Items are not allowed
}
}
}
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.