0
votes

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 kendo 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();
    });

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

1

1 Answers

0
votes

This is because save changes is an asynchronous function. So the rest of the code will execute not matter the result of the save function. A simple and quick method will be to set a global variable just before you call save changes. Then once the save result is received from server, the grid will fire the onRequestEnd method. You can open the popup window there if the global variable is set.

$("#btnAddProject").click(function (e) {
    var grid = $("#Grid").data("kendoGrid");
    isSavingChanges = true;
    grid.saveChanges();
});

function gridRequestEnd(e) {
 if (e.Response){//Response is not null means it is most probably ajax result
  if(isSavingChanges == true){
    isSavingChanges = false;
    var myWindow = $("#AddProjectWindow");
    myWindow.data("kendoWindow").open();
    myWindow.data("kendoWindow").center();
  }     
 }
}