I have a sub-grid in a details template, that allows records to be inserted and deleted. I can put an error handler on the datasource, which will show an error message if the action fails, however as the grid name is dynamically generated, I can't see a way to call preventdefault(), to stop the failed inserts / deletes being displayed in the grid.
How can I get the grid name to call the preventDefault method?
Grid:-
<script id="subdetailsTemplate" type="text/kendo-tmpl"> @(Html.Kendo().Grid<EVASLogicLibrary.UserDirectorateMap>() .Name("MapGrid_#=ID#") .Columns(columns => { columns.Bound(o => o.ID).Title("ID"); columns.ForeignKey(p => p.DirectorateID, (System.Collections.IEnumerable)ViewData["directorates"], "ID", "DirectorateName").Title("Directorate").Width(200); //columns.Bound(o => o.UserID).Title("User"); columns.Command(command => { command.Destroy(); command.Edit(); }); }) .Events(e=>e.DataBound("gridBind")) .ToolBar(tb => tb.Create()) .Editable(e=>e.Mode(GridEditMode.InLine)) .DataSource(dataSource => dataSource .Ajax() .PageSize(10) .Events(e=>e.Error("Suberror")) .Model(m=>{ m.Id(p => p.ID); m.Field(p => p.ID).Editable(false); }) .Read(read => read.Action("RD_Maps", "Users", new { UserId = "#= ID #" })) .Create(u=>u.Action("InsertMap", "Users", new { UId = "#= ID #" })) .Update(u => u.Action("InsertMap", "Users")) .Destroy(u => u.Action("DeleteMap", "Users")) ) .Pageable(p => p.Refresh(true)) .ToClientTemplate() ) </script>Error handler:-
function Suberror(e) { if (e.errors) { var message = "Errors:\n"; $.each(e.errors, function (key, value) { if ('errors' in value) { $.each(value.errors, function () { message += this + "\n"; }); } }); alert(message); } }And the main grid error handler (that I want to replicate the functionality of:-
function error(e) { if (e.errors) { var message = "Errors:\n"; $.each(e.errors, function (key, value) { if ('errors' in value) { $.each(value.errors, function () { message += this + "\n"; }); } }); var grid = $("#Grid").data("kendoGrid"); grid.one("dataBinding", function (e) { e.preventDefault(); // cancel grid rebind if error occurs }); alert(message); } }Thanks