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

Grid sync call on errror

1 Answer 370 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Valérie
Top achievements
Rank 1
Valérie asked on 21 Oct 2015, 02:23 PM

I use razor Html Helper to create a Kendo UI Grid. The grid is created so the edition of a record is done via a popup window form. Here is the code 

@(Html.Kendo().Grid<MyObject>()
              .Name("grid")
              .Editable(edit => edit
                  .Enabled(true)
                  .Mode(GridEditMode.PopUp)
              )
              .Columns(columns =>
              {
                  // Column declaration
              })
              .ToolBar(toolbar =>
              {
                  toolbar.Create());
              })
              .DataSource(dataSource => dataSource
                  .Ajax()
                  .Model(model => model.Id(m => m.Id))
                  .ServerOperation(false)
                  .Events(e =>
                  {
                      e.Error("error_handler");
                      e.Sync("sync_handler");
                  })
                  .Read("Read", "MyController")
                  .Create(c => c.Action("Create", "MyController"))
                  .Update(u => u.Action("Edit", "MyController"))
              )
        )​

 

I set a handler on both error and sync event of my datasource. The sync handler force a read from the server since some data must be refreshed on create and update operation. The error handler is supposed to prevent the refresh of the grid if an error occur on create or update. Here are both of my handlers

 

function error_handler(e) {
        if (e.errors) {
 
            $('#grid').data("kendoGrid").one("dataBinding", function (ss) {
                ss.preventDefault(); // cancel grid rebind if error occurs
            });   
        }
    }
 
    function sync_handler(e) {
        e.sender.read();
    }

My problem is that even if i call ss.preventDefault on the sync action, my sync handler is call anyway and the call to e.sender.read() cause my popup window form to close. If i remove my sync handler, the ss.preventDefault call prevent my popup window form to close correctly, so the problem really is about the sync handler which is always call, even on error. Any idea how I can handle this ?

1 Answer, 1 is accepted

Sort by
0
Kiril Nikolov
Telerik team
answered on 23 Oct 2015, 08:13 AM

Hello Sylvain,

 

Binding to the dataBinding event, is a bit too late and therefore the event is not prevented. I would suggest you to implement a global flag that will handle the state of the error operation.

 

Regards,
Kiril Nikolov
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
Tags
Grid
Asked by
Valérie
Top achievements
Rank 1
Answers by
Kiril Nikolov
Telerik team
Share this question
or