This is a migrated thread and some comments may be shown as answers.

How do know grid.savechanges() method is success or fail

3 Answers 96 Views
Grid
This is a migrated thread and some comments may be shown as answers.
sandy
Top achievements
Rank 1
Iron
Veteran
sandy asked on 07 Mar 2021, 01:54 PM

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

3 Answers, 1 is accepted

Sort by
0
Nikolay
Telerik team
answered on 10 Mar 2021, 04:45 PM

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.

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/.

0
sandy
Top achievements
Rank 1
Iron
Veteran
answered on 11 Mar 2021, 06:32 AM

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

0
Nikolay
Telerik team
answered on 15 Mar 2021, 12:37 PM

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/.

Tags
Grid
Asked by
sandy
Top achievements
Rank 1
Iron
Veteran
Answers by
Nikolay
Telerik team
sandy
Top achievements
Rank 1
Iron
Veteran
Share this question
or