When I change an amount, tick the checkbox etc, it triggers some javascript, which includes some code to set another field on the dataItem, so `dataItem.Set ("Amount", 0);`
I can set it using `dataItem.Amount = 0;` , but then I also need to update the contents of the <td> cell. When I do set I obviously don't want the dirty flag clearing from other cells, as I haven't clicked 'Save changes' yet, so they are still 'dirty'.
I can't find any documentation on the .set method. It's as though it is firing other events off.
Any advice would be appreciated.
and the JS.
I can set it using `dataItem.Amount = 0;` , but then I also need to update the contents of the <td> cell. When I do set I obviously don't want the dirty flag clearing from other cells, as I haven't clicked 'Save changes' yet, so they are still 'dirty'.
I can't find any documentation on the .set method. It's as though it is firing other events off.
Any advice would be appreciated.
@(Html.Kendo().Grid<OurViewModel>()
.Name(
"Grid"
)
.DataSource(dataSource => dataSource
.Ajax()
.Model(model =>
{
model.Id(a => a.ID);
model.Field(a => a.Reference).Editable(
false
);
model.Field(a => a.Narrative).Editable(
false
);
model.Field(a => a.Include).Editable(
true
);
model.Field(a => a.Amount).Editable(
true
);
})
.Batch(
true
)
.Read(read => read.Action(
"_Read"
,
"Home"
))
.Update(update => update.Action(
"_Update"
,
"Home"
))
.ServerOperation(
false
)
.Events(events =>
{
events.Change(
"onDataSourceChange"
);
})
)
.Columns(columns =>
{
columns.Bound(a => a.Reference).Title(
"Reference"
);
columns.Bound(a => a.Narrative).Title(
"Narrative"
);
columns.Template(@<text></text>).Title(
"Include?"
)
.ClientTemplate(
"<input type='checkbox' #= Include ? checked='checked': '' # onclick='updateAmount(this, \"#= ID#\")' />"
);
columns.Bound(a => a.Amount).Title(
"Amount"
);
})
.Events(events =>
{
events.Save(
"onSave"
);
events.SaveChanges(
"onSaveChanges"
);
})
.ToolBar(toolbar =>
{
toolbar.Save();
})
.Editable(editable => editable.Mode(GridEditMode.InCell))
)
and the JS.
function
updateAmount(cb, ourID) {
var
checked = $(cb).is(
':checked'
);
var
grid = $(
'#Grid'
).data().kendoGrid;
var
dataItem = grid.dataSource.get(ourID);
dataItem.set(
"Include"
, checked);
if
(checked) {
dataItem.set(
"Amount"
, dataItem.get(
"OriginalAmount"
));
}
else
{
dataItem.set(
"Amount"
, 0);
}
}