How to determine if there were validation errors after calling (Kendo) grid.SaveChanges() in javascript -
i call grid.savechanges() in javascript function. grid using inline editing mode.
my problem if there client side validation errors example invalid date format, must not execute dom operations. unfortunately grid.savechanges() has no return value , searching keyword 'valid' in grid documentation page has no result. (teleport kendo grid api documentation)
so: how can determine if there validation errors after savechanges() or data sync-ed persistent store?
thx in advance
i'm assuming using mvc wrappers calling grid.savechanges() part of script. since you're using inline editing mode, means you're using ajax. if assumptions correct, when call savechanges() controller action specified in wrapper executed. if hook .error event can execute whatever script needs executed (even if that's setting variable check in other parts of script). have @ ajax editing portion of getting started on kendo's website. razor code similar following (some of extraneous, pulled out of production code , modified slightly):
@(html.kendo().grid(model) .name("grid") .columns(cols => { cols.bound(p => p.columna); }) .editable(edit => edit.enabled(true).mode(grideditmode.incell)) .datasource(ds => ds .ajax() .autosync(false) .model(model => { model.id(p => p.columnid); }) // configure ru --> .read(read => read.action("_myread", "mycontroller").data("additionaldata")) .update(update => update.action("_myupdate", "mycontroller").data("additionaldata")) //.serveroperation(false) .batch(true) .events(events => events .error("onerror") ) ) // <-- configure ru .pageable(page => page.pagesizes(new int[] { 10, 25, 50, 100 }).enabled(true)) .groupable(group => group.enabled(true)) .filterable(filter => filter.enabled(true).extra(false)) .sortable(sort => sort.enabled(true).sortmode(gridsortmode.singlecolumn).allowunsort(true)) .navigatable(nav => nav.enabled(true)) .resizable(resizing => resizing.columns(true)) .reorderable(reorder => reorder.columns(true)) ) then onerror script this:
function onerror(e, status) { if (e.errors) { var message = "the following errors have occurred , changes discarded:\n"; $.each(e.errors, function (key, value) { if (value.errors) { message += value.errors.join("\n"); } }); alert(message); var grid = $("#grid").data("kendogrid"); grid.cancelchanges(); } }
Comments
Post a Comment