This is a migrated thread and some comments may be shown as answers.

Row removed on cancelled edit

1 Answer 273 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Steve
Top achievements
Rank 1
Steve asked on 18 Feb 2018, 06:58 PM

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();
                }
            }

1 Answer, 1 is accepted

Sort by
0
Steve
Top achievements
Rank 1
answered on 19 Feb 2018, 04:26 PM

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

Tags
Grid
Asked by
Steve
Top achievements
Rank 1
Answers by
Steve
Top achievements
Rank 1
Share this question
or