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