Hi,
I have a kendo MVC grid in a page.in that page i have button. when i click button i want to open a kendowindow popup.
so here is my issue.
when i am clicking that button am saving grid values and i am opening kendo window popup. so if i have a errors in grid then i dont want to open kendow window popup. how to achieve this. below is my button click code.
$("#btnAddProject").click(function (e) {
var grid = $("#Grid").data("kendoGrid");
grid.saveChanges();
var myWindow = $("#AddProjectWindow");
myWindow.data("kendoWindow").open();
myWindow.data("kendoWindow").center();
});
5 Answers, 1 is accepted
Hello Sandy,
I can suggest setting a global flag that will change to false if an error is thrown in the Error DataSource event handler.
- https://docs.telerik.com/aspnet-mvc/api/Kendo.Mvc.UI.Fluent/DataSourceEventBuilder#errorsystemstring
For example:
var failed = false;
...
.DataSource(dataSource => dataSource
.Ajax()
.....
.Events(events => events.Error("handleErrors"))
))
..
<script>
function handleErrors() {
failed = true;
}
function myFunction() {
var grid = $("#grid").data("kendoGrid");
grid.saveChanges();
if(!failed) {
wnd.center().open();
}
}
</script>
Here is a small Dojo demo demonstrating this:
Let me know if you have any questions.
Regards,
Nikolay
Progress Telerik
Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Here am included below datasource events. events.Error("error_handler").RequestEnd("gridRequestEnd")
but these datasources functions are calling after click event finish. but i want wait for grid.saveChanges() to finish and check whether save is success or fail.
if fail i dont want to open kendo popup. here datasource functions are calling after finishing button click function
Hi Sandy,
You can move the executing of the window initialization after the Error data source event has fired as below:
function myFunction() {
var grid = $("#grid").data("kendoGrid");
grid.saveChanges();
setTimeout(function () {
if(!failed) {
wnd.center().open();
}
},300)
}
</script>
Please try this and let me know if it helps.
Regards,
Nikolay
Progress Telerik
Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Hi Sandy,
I have another solution.
let grid= $("#grid").data("kendoGrid");
if (grid) {
grid.dataSource.transport.options.update.async = false;
grid.dataSource.transport.options.create.async = false;
grid.dataSource.transport.options.destroy.async = false;
grid.saveChanges()
};

Rather than use the grid saveChanges() function, I would suggest accessing the grid's dataSource object and call it's sync() function as this returns a promise.
let grid= $(`#${gridId}`).data("kendoGrid"); grid.dataSource.sync().then(function () { console.log(`Data synced.`); });