Grid ForeignKey In-Line Editing not working

9 posts, 1 answers
  1. Tyler
    Tyler avatar
    46 posts
    Member since:
    Nov 2013

    Posted 16 Apr 2015 Link to this post

    I just updated to release '2015.1.318' and a Grid that was working fine with several ForeignKey columns bound to Guid and selectlists is now not working. I add and update In-Line on the grid. Now when I CREATE a new Entity inline - the editor displays all the data perfectly but the data sent to the server does not include the values selected for the ForeignKey columns. These are sent as Empty Guids i.e.00000000-0000-0000-0000-000000000000.

    Note - when I UPDATE an existing entity it all works fine, the problem is only when I CREATE\INSERT.

    The code for the Grid is below and the EditorTemplate for the ForeignKey column is also there.

     

    Grid

    <script type="text/javascript">
      function gridEntityAssignments_CreateData() {
          return {
            assignedTo: "@(assignedTo)",
            assignedToOid: "@(assignedToOid)",
          };
      }
    </script>
    @*All Required*@
    @Html.Hidden("IsAssignments", isAssignments)
    @Html.Hidden("AssignmentsAssignedToOid", assignedToOid)
    @Html.Hidden("AssignmentsAssignedTo", assignedTo)
     
    <div style="width: 100%">
      @(Html.Kendo().Grid<Mallon.AssignedTo.Models.ViewGridAssignment>()
      .Name("GridEntityAssignments")
      .AutoBind(isAssignments) //if false - Report not loaded on page initialise
      .HtmlAttributes(new { @class = "ignore" })
      .ToolBar(toolbar =>
      {
        toolbar.Create().HtmlAttributes(new { @class = "dfw-ignoreDirtyLink" });
      })
      .Editable(editable => editable.Mode(GridEditMode.InLine))
      .Scrollable(s => s.Height("auto"))
      .Columns(columns =>
      {
        columns.Bound(p => p.Oid).Visible(false);
        columns.ForeignKey(p => p.UserOid, (System.Collections.IEnumerable)ViewData["AssignmentUsers"], "Value", "Text").EditorTemplateName("GridForeignKeyWithSelect").Title("User");
        columns.ForeignKey(p => p.AssignmentTypeOid, (System.Collections.IEnumerable)ViewData["AssignmentTypes"], "Value", "Text").EditorTemplateName("GridForeignKeyWithSelect").Title("Type");
        columns.Bound(p => p.Info).EditorTemplateName("GridTextArea");
        columns.Command(command => { command.Edit(); command.Destroy(); }).Width(172);
      })
      .DataSource(dataSource => dataSource
        .Ajax()
        .AutoSync(false)
        .Model(model =>
        {
          model.Id(p => p.Oid);
          model.Field(p => p.Oid).DefaultValue(Guid.Empty);
        })
        .Events(e => e.Error("handleAjaxError"))
        .Destroy(update => update.Action("Assignments_GridDelete", "Assignment"))
        .Update(update => update.Action("Assignments_GridUpdate", "Assignment"))
        .Create(update => update.Action("Assignments_GridCreate", "Assignment").Data("gridEntityAssignments_CreateData"))
        .Read(read => read.Action("Assignments_GridRead", "Assignment", new { assignedToOid = assignedToOid }))
      )
    )
     
    </div>

     

     Editor Template

     

    @model object
     
    @(
     Html.Kendo().DropDownListFor(m => m)
            .BindTo((SelectList)ViewData[ViewData.TemplateInfo.GetFullHtmlFieldName("") + "_Data"]).OptionLabel("Please Select")
    )

     

     

     

     

     

     

     

     

     

     

     

  2. Tyler
    Tyler avatar
    46 posts
    Member since:
    Nov 2013

    Posted 16 Apr 2015 in reply to Tyler Link to this post

    I believe the problem is that the dropdownlists associated with the ForeignKey columns are not firing their select event when I select my selection. If I select an item then select another different item then the correctly selected data gets sent.

    Any idea how to fix this?

  3. UI for ASP.NET MVC is VS 2017 Ready
  4. Tyler
    Tyler avatar
    46 posts
    Member since:
    Nov 2013

    Posted 17 Apr 2015 in reply to Tyler Link to this post

    Alright this functionality is broken. The first select event on the ForeignKey dropdownlist is not updating the model values. I have to explicitly set dropDownList values using the onSave event as shown below. Telerik why dosnt this work?

    Heres the updates code with the Save event.

      @(Html.Kendo().Grid<Mallon.AssignedTo.Models.ViewGridAssignment>()
      .Name("GridEntityAssignments")
      .AutoBind(isAssignments) //if false - Report not loaded on page initialise
      .HtmlAttributes(new { @class = "ignore" })
      //Save Event is required because Inline eding with DropDownLists (ForegnKeys) dosnt seem to pick up the first select
      //event. So even when I change\select the value the selected value is not populating the model with the data. This
      //is only a problem on the first select.
      .Events(events => events.Edit("onEdit_GridEntityAssignments").Save("onSave_GridEntityAssignments"))
      .ToolBar(toolbar =>
      {
        toolbar.Create().HtmlAttributes(new { @class = "dfw-ignoreDirtyLink" });
      })
      .Editable(editable => editable.Mode(GridEditMode.InLine))
      .Scrollable(s => s.Height("auto"))
      .Columns(columns =>
      {
        columns.Bound(p => p.Oid).Visible(false);
        columns.ForeignKey(p => p.UserOid, (System.Collections.IEnumerable)ViewData["AssignmentUsers"], "Value", "Text").EditorTemplateName("GridForeignKeyWithSelect").Title("User");
        columns.ForeignKey(p => p.AssignmentTypeOid, (System.Collections.IEnumerable)ViewData["AssignmentTypes"], "Value", "Text").EditorTemplateName("GridForeignKeyWithSelect").Title("Type");
        columns.Bound(p => p.Info).EditorTemplateName("GridTextArea");
        columns.Command(command => { command.Edit(); command.Destroy(); }).Width(172);
      })
      .DataSource(dataSource => dataSource
        .Ajax()
        .AutoSync(false)
        .Model(model =>
        {
          model.Id(p => p.Oid);
          model.Field(p => p.Oid).DefaultValue(Guid.Empty);
        })
        .Events(e => e.Error("handleAjaxError"))
        .Destroy(update => update.Action("Assignments_GridDelete", "Assignment"))
        .Update(update => update.Action("Assignments_GridUpdate", "Assignment"))
        .Create(update => update.Action("Assignments_GridCreate", "Assignment").Data("gridEntityAssignments_CreateData"))
        .Read(read => read.Action("Assignments_GridRead", "Assignment", new { assignedToOid = assignedToOid }))
      )
    )

    Javascript events:

     

    //Used to set the initial value for ForeignKey dropDownLists
    function onEdit_GridEntityAssignments(e) {
      if (e.model.isNew()) {
        $("#GridEntityAssignments tbody [data-role=dropdownlist]").each(function () {
          var ddl = $(this).data("kendoDropDownList");
          if (ddl) {
            ddl.select(0);
          }
        })
      }
    }
     
    //This is required because Inline eding with DropDownLists (ForegnKeys) dosnt seem to pick up the first select
    //event. So even when I change\select the value the selected value is not populating the model with the data. This
    //is only a problem on the first select.
    function onSave_GridEntityAssignments(e) {
      $("#GridEntityAssignments tbody [data-role=dropdownlist]").each(function () {
        var ddl = $(this).data("kendoDropDownList");
        if (ddl) {
          var v = ddl.value();
          var p = ddl.list.attr('id').replace('-list', '');
          if (p) e.model.set(p, v);
        }
      })
    }

     

     

     

     

     

     

     

     

  5. Answer
    Boyan Dimitrov
    Admin
    Boyan Dimitrov avatar
    1746 posts

    Posted 20 Apr 2015 Link to this post

    Hello Tyler,

    We have fixed this issue and it is already included in our service pack release (2015.1.408). 

    I would like to apologize for any inconveniences caused. 

    Regards,

    Boyan Dimitrov

    Telerik

     

    See What's Next in App Development. Register for TelerikNEXT.

     
  6. Terry
    Terry avatar
    31 posts
    Member since:
    Jun 2016

    Posted 02 Sep in reply to Boyan Dimitrov Link to this post

    Is there any chance this problem has been reintroduced?  I'm seeing the exact same results.  On an insert, the foreign key field isn't getting updated.  I went into the database and set a value - and then the update worked.  But update doesn't work if the value is initially null.  I am on version 2016.2.714.
  7. Boyan Dimitrov
    Admin
    Boyan Dimitrov avatar
    1746 posts

    Posted 06 Sep Link to this post

    Hello Terry,

    Could you please try to set valuePrimitive option to true for the DropDownList editor of the foreign key column and let us know how that worked? 

    Regards,
    Boyan Dimitrov
    Telerik by Progress
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  8. Terry
    Terry avatar
    31 posts
    Member since:
    Jun 2016

    Posted 06 Sep in reply to Boyan Dimitrov Link to this post

    Sorry - I can't figure out how to set that option in a Razor view.  Here's how I'm defining the dropdownlist.  If you can show me how to add that option, then I'll try it.  Thanks.
    columns.ForeignKey(c => c.GenerationTypeID, (System.Collections.IEnumerable)@ViewBag.gentypes, "Value", "Text").Title("Generation");
  9. Konstantin Dikov
    Admin
    Konstantin Dikov avatar
    1796 posts

    Posted 07 Sep Link to this post

    Hello Terry,

    The property should be set to the editor template and not in the column definition. You should have a GridForeignKey editor template within your Views/Shared/EditorTemplates folder with the DropDownList:
    @(
     Html.Kendo().DropDownListFor(m => m)       
            .BindTo((SelectList)ViewData[ViewData.TemplateInfo.GetFullHtmlFieldName("") + "_Data"])
            .ValuePrimitive(true)
    )

    Hope this helps.


    Regards,
    Konstantin Dikov
    Telerik by Progress
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  10. Terry
    Terry avatar
    31 posts
    Member since:
    Jun 2016

    Posted 08 Sep in reply to Konstantin Dikov Link to this post

    Konstantin - that worked.  Thanks.

    For anyone else reading this.  I didn't make any changes to my view.  What Konstantin showed me to change was the GridForeignKey Editor Template. 

Back to Top
UI for ASP.NET MVC is VS 2017 Ready