Row removed on cancelled edit

2 posts, 0 answers
  1. Steve
    Steve avatar
    21 posts
    Member since:
    Feb 2015

    Posted 18 Feb 2018 Link to this post

    I've seen several somewhat related threads, but none have helped me. When I click edit and then cancel, the item is removed from the grid (not the database). What is different about this scenario is I am using a composite key EventId + NameId + LocationId where each record will have either a NameId or a LocationId, but not both.

    When I step through the code, my popup is displayed and bound as expected. When I click the cancel button it removes my edited item from the grid. I've tried jumping into the datasource change and sync events and doing an e.preventDefault() when I know this is the cancel of an edit, but that does not work (record disappears after that). Is there any spot I can jump in and intercept the removal of the item? Or is there something special I need to configure when using a composite key where one part will be null or zero? I get it that kendo must be thinking I am cancelling an insert instead of an update and it is probably related to my composite key use. My other grids work fine. Thanks.

     

                @(Html.Kendo().Grid<ContactViewModel>().Name("contactGrid")
                      .Columns(column =>
                      {
                          column.Template(t => { }).Title("Edit").Width(10)
                              .ClientTemplate(@"<a class='btn btn-info btn-xs k-grid-edit' title='Edit this contact.'><i class='fa fa-edit'></i></a>");
                          column.Bound(p => p.IncidentID).Hidden(true);
                          column.Bound(p => p.NameID).Hidden(true);
                          column.Bound(p => p.LocationID).Hidden(true);

                          ...

                      })
                      .Editable(editable => editable.Mode(GridEditMode.PopUp)
                          .TemplateName("EventContact")
                      .Filterable().Sortable().Pageable().ColumnMenu()
                      .Events(ev =>
                      {
                          ev.Edit("onContactGridEdit");
                      })
                      .DataSource(dataSource => dataSource
                          .Ajax()
                          .PageSize(10)
                          .Model(m =>
                          {
                              m.Id(c => new { c.IncidentID, c.NameID, c.LocationID });
                              m.Field(c => c.IncidentID).DefaultValue(Model.IncidentID);
                          })
                          .Read(read => read.Action("Read", "Contact", new { incidentID = Model.IncidentID }))
                          .Create(update => update.Action("Create", "Contact"))
                          .Update(update => update.Action("Update", "Contact"))
                          .Destroy(update => update.Action("Delete", "Contact"))
                      .Events(events =>
                      {
                          events.Change("incidentUpdate.onDataSourceChange");
                      })  )  )

                function dataSourceChange(e) {

                    if (e.action === "remove" && !e.items[0].ContactIsNew) {   // this is a field I set to determine if it is a create or update
                        e.preventDefault();
                    }
                }

                function dataSourceSync(e) {

                    if (e.action === "remove" && !e.items[0].ContactIsNew) {   // this is a field I set to determine if it is a create or update
                        e.preventDefault();
                    }
                }

  2. Steve
    Steve avatar
    21 posts
    Member since:
    Feb 2015

    Posted 19 Feb 2018 Link to this post

    OK, looks like composite keys are not supported (http://kendoui-feedback.telerik.com/forums/127393-kendo-ui-feedback/suggestions/3398586-support-composite-keys-in-the-datasource-id-proper).

    I was able to work around this using a pseudo key as suggested here: https://www.telerik.com/forums/composite-datakey-in-kendo-ui-mvc#JlhcEtSyAEqMWaW6TjnDKQ

Back to Top