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