Incell editing with a foreign key dropdown list

0 Answers 46 Views
AP asked on 18 Jan 2022, 09:07 AM

I have a grid, with in-cell editing where only one field is editable, which is a foreign key field with a dropdown list. The grid is set to autosync, and batch mode is off.

This works fine, updating the records after an option is selected from the dropdown list. However, on the server-side I have implemented some consistency checks, to see if a user updates a record after it has been updated by another user, but before their grid was refreshed. This works, and I can get an error message displayed.

However, what I need to happen once an error occurs, is for the record to be reset back to its original state. At the moment, the selected item on the dropdown list is shown, along with a dirty flag.  I have tried calling a datasource read on the grid, but this isn't called.

How can I reset the grid after an error?

The code is :-

                     //.Events(e => e.Edit("onEdit"))
                     .Columns(col =>
                         col.Bound(o => o.ID).Title("ID");
                         col.Bound(o => o.PatientID).Title("Patient ID");
                         col.Bound(o => o.PatientName).Title("Patient Name");
                         col.Bound(o => o.Site).Title("Site");

                         col.ForeignKey(p => p.ReasonID, (System.Collections.IEnumerable)ViewData["reasons"], "ID", "Reason")

                         //col.Command(command => { command.Edit(); command.Destroy(); });


                        .Editable(editable => editable
                         .DataSource(ds => ds
                         .Events(events => events.Error("errorHandler"))

                         .Model(m =>

                         { m.Id(p => p.ID);
                             m.Field(p => p.ID).Editable(false);
                             m.Field(p => p.PatientID).Editable(false);
                             m.Field(p => p.PatientName).Editable(false);
                             m.Field(p => p.Site).Editable(false);
                             m.Field(p => p.Ward).Editable(false);
                             m.Field(p => p.BedSpace).Editable(false);
                             m.Field(p => p.CurrentLOS).Editable(false);
                             m.Field(p => p.LOSGroup).Editable(false);
                             m.Field(p => p.Pathway).Editable(false);
                             m.Field(p => p.LastFlaggedAsR2R).Editable(false);

                 //.Events(events => events.Error("error"))
                 .Read(rd => rd.Action("RD_RightToResideList", "Home").Data("filter")

                  .Create(create => create.Action("NA", "Home"))
                 .Update(update => update.Action("UpdateRecord", "Home"))
                 .Destroy(delete => delete.Action("NA", "Home"))
                  .Pageable(p => p.Refresh(true))


<script type="text/javascript">

    function filter()
        return {
            AuditNumber: 1


    function errorHandler(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");

  "dataBinding", function (e) {

                e.preventDefault();   // cancel grid rebind if error occurs



commented on 18 Jan 2022, 09:39 AM

It seems if I change    $("Grid").data("kendoGrid");  to  

 var grid = $("#Grid").data("kendoGrid");;


The grid refresh works..

Patrick | Technical Support Engineer, Senior
Telerik team
commented on 20 Jan 2022, 03:02 PM

Great, and thanks for the update!  I'm glad the Kendo UI Grid is resetting and refreshing for you.  

No answers yet. Maybe you can help?

Asked by
Share this question