Hello,
we have a Grid that is bound to an IEnumerable Property of the ViewModel being supplied by the server as you can see in the following code snippet:
01.
@(Html.Kendo().Grid<AktionsTracker.Pages.PromotionEditModel.ModelDTO>(Model.Promotion.Models)
02.
.Name(ModelGrid)
03.
.Columns(c =>
04.
{
05.
c.ForeignKey(
"ModelId"
, Model.Models,
"ModelId"
,
"ModelCode"
).Title(
"Modellcode"
).Width(100);
06.
c.ForeignKey(
"ModelId"
, Model.Models,
"ModelId"
,
"ModelName"
).Title(
"Modellbezeichnung"
).Width(200);
07.
c.Bound(m => m.Absolute).Width(150);
08.
c.Bound(m => m.Relative).Width(150);
09.
c.Command(c => c.Edit());
10.
c.Command(c => c.Destroy());
11.
})
12.
// more code
13.
.DataSource(c =>
14.
{
15.
c.Custom()
16.
.Schema(s =>
17.
{
18.
s.Model(m =>
19.
{
20.
m.Id(
"ModelId"
);
21.
m.Field(
"ModelId"
,
typeof
(
int
)).Editable(
false
);
22.
m.Field(
"Absolute"
,
typeof
(Decimal?));
23.
m.Field(
"Relative"
,
typeof
(Decimal?));
24.
});
25.
});
26.
})
27.
)
We now want to programmatically insert a new record with a specific Id (guaranteed to be unique and have an entry in the ForeignKey-Collections) and directly put the Row into Edit-Mode.
At first, we tried to simply call grid.addRow() and handle the beforeEdit event to set the ModelId but this did not work out since the ModelId has to be non-Editable.
Therefore, we have resorted to a different approach where we execute the following code in a javascript function:
1.
var grid = $("#@ModelGrid").data("kendoGrid");
2.
grid.dataSource.add({ ModelId: value, Absolute: null, Relative: null });
3.
grid.editRow($("#@ModelGrid tbody tr:last-of-type"));
i.e. we add the pre-filled record to the datasource of the grid and manually start the editing via the call to editRow.
The problem is the following:
- Record is added and edit-mode is entered
- We manually set the required properties and press the Update button
- We press the Edit button on the same row
- We press Cancel to end the editing without saving changes => as a result the row disappears even though it has been previously saved!
It does not matter how often we have update the record with valid data, as soon as we press Cancel the record will disappear every time.
I want to reiterate that it is fine and *intended* that the row disappears if Cancel is clicked directly after adding the row. However, having it disappear after multiple succesfull updates is not what we want at all.
How can we fix this behaviour?
Best Regards