Keno Grid Update not updating Grid DataSource

2 posts, 0 answers
  1. Dan
    Dan avatar
    37 posts
    Member since:
    Oct 2013

    Posted 17 Nov 2016 Link to this post

    I have a Telerik Grid for MVC 4 using Kendo 2014.
    The grid has a 1 foreign key and I am using the foreign key template.

    The Grid is working properly as far as CRUD operations, however, the GridData source is not getting updated. Consequently when trying to use the new updated values from the grid.dataSource (visible in the grid) I am getting the old values:

    I have tried to update the datasource but am not able to get any of the prescribed datasource events events triggered  other than events.change which is not specific enough.

    Here is my Grid:

                //.HtmlAttributes(new { style = "height: 480px; margin-left: 260px" })
                  .Events(events => events.Edit("onEdit"))//.Events(events => events.Change("onChange"))
                  .Columns(columns =>
                        columns.Bound(p => p.peqID).Width(20).Title("ID");
                        columns.Bound(p => p.peqName).Width(120).Title("Name");
                        columns.Bound(p => p.peqTag).Width(120).Title("Tag");
                        columns.Bound(p => p.peqDescription).Width(200).Title("Description");
                        columns.ForeignKey(p => p.eqtID, (System.Collections.IEnumerable)ViewData["EqptTypes"], "TypeID", "Type").Title("Eqpt Type").Width(200);
                      //columns.Bound(p => p.eqtID).Width(120).ClientTemplate("<span tabindex='0' class='k-widget k-dropdown k-header' unselectable='on'><span class='k-dropdown-wrap k-state-default' unselectable='on'><span class='k-input' unselectable='on'>Select Type</span><span class='k-select'><span class='k-icon k-i-arrow-s'>select</span></span></span><input name='Type' id='Type' style='display: none;' type='text' data-role='dropdownlist'></span>");
                       columns.Bound(p => p.peqID).Width(10).Title("Edit Sizes")
                            .ClientTemplate("<button type='button' onclick=\"EditProcEquipment(this);\" text='text'  class='k-button k-button-icontext k-grid-edit' style='min-width: 30px; min-height: 25px;  height: 25px; padding-top: 0; padding-right: 0;'><span class='k-icon k-edit'></button>");
                        columns.Bound(p => p.peqActive).Width(30);
                        columns.Command(commands =>
                            commands.Edit().HtmlAttributes(new { style = "min-width:64px;width:80px" });
                      .ToolBar(toolbar => { toolbar.Create(); toolbar.Save(); }) // toolbar.Save(); })
                       //.ToolBar(toolBar => toolBar.Template("<a class='k-button k-button-icontext k-grid-add' href='#' onlick='customCreateCmd()'>Add new record</a>"))
                        .HtmlAttributes(new { style = "veritcal-align:top" })
                       .Selectable(s => s.Mode(GridSelectionMode.Single))
                                      //.Selectable(s => s.Mode(GridSelectionMode.Multiple))
                                      //.Editable(editable => editable.Mode(GridEditMode.InLine)) // Use inline editing mode.
                      .Editable(editable => editable.Mode(GridEditMode.InCell))
                      .DataSource(dataSource =>  dataSource
                      .Events(events => events.Error("errorHandler").Sync("onSync").RequestEnd("onRequestEnd"))//.Sync("sync_handler"))
                       //.Events(events => events.RequestEnd("onRequestEnd"))
                       //.Events(events => events.Change("onChange"))
                       //.Events(events => events.Push("onPush"))
                       //.Events(events => events.Edit("onEdit"))
                      .Model(model =>
                                model.Id(p => p.peqID); // Specify the property which is the unique identifier of the model.
                                model.Field(p => p.peqID).Editable(false); // Make the ProductID property not editable.
                                //model.Field(p => p.Type).DefaultValue(new PMTWebReconcile.Models.EquipTypeViewModel());
                                model.Field(p => p.eqtID).DefaultValue(16);
                                model.Field(p => p.plsID);//need to come from treeview selector
                               //model.Field(p => p.plsID).DefaultValue(Html.Kendo().TreeView("tvPH").select());
                             .Read(read => read.Action("ForeignKeyColumn_Read", "PlantHierArchy", new { plsID = (subUnitID) }))
                             .Create(create => create.Action("ForeignKeyColumn_Create", "PlantHierArchy"))
                             .Update(update => update.Action("ForeignKeyColumn_Update", "PlantHierArchy").Type(HttpVerbs.Post).Data("UpdateHandler"))

    And my corresponding Update and Insert which are updating the Database Successfully.

           public ActionResult ForeignKeyColumn_Create([DataSourceRequest] DataSourceRequest request,
               [Bind(Prefix = "models")]IEnumerable<ProcEquipViewModel> procEqs)
               var results = new List<ProcEquipViewModel>();
               if (procEqs != null && ModelState.IsValid)
                   foreach (var proc in procEqs)
               return Json(results.ToDataSourceResult(request, ModelState));
          public ActionResult ForeignKeyColumn_Update([DataSourceRequest] DataSourceRequest request,
              [Bind(Prefix = "models")]IEnumerable<ProcEquipViewModel> procEqs)
              if (procEqs != null && ModelState.IsValid)
                  foreach (var proc in procEqs)
              DataSourceResult DSR = procEqs.ToDataSourceResult(request, ModelState);
              JsonResult JR = Json(DSR);
              return JR;

    How can I update my data source?
    additionally it would also be nice to be able to capture and update other update items but The grid.datasource is the most important.

  2. Kostadin
    Kostadin avatar
    1733 posts

    Posted 21 Nov 2016 Link to this post

    Hi Dan,

    I examined the provided code but as far as I can see it looks correct. Could you please check out the following example and let me know how it differs from your real setup? I would appreciate if you can replicate the issue in a small runnable sample in order to examine it locally.

    Telerik by Progress
    Telerik UI for ASP.NET MVC is ready for Visual Studio 2017 RC! Learn more.
Back to Top