In the editor template of the Kendo Grid, I'd like to save changes when certain event has been triggered. I'd like to keep the window open, so user can continue to update other fields. I save the changed by the following codes in the editor template:
function innerGridEditEvent(e) {
var model = e.model;
if (!model.isNew)
return;
var Id = parseInt($("#Id").val(), 10);
if (!Id) {
var masterGrid = $("#masterGrid").data('kendoGrid');
masterGrid.saveChanges();
}
}
And I keep the popup window open by using this function on SaveChanges
event of the main Grid.
function masterSaveChanges(e) {
var grid = e.sender;
grid.bind("dataBinding", function (e) {
e.preventDefault();
})
}
It works fine, but I need to have the newly created Id
. In other words I want an updated model.
If it matters or you want to suggest any workarounds, inside the editor template, I have another grid and I'd like to set the read
and create
data of that Grid.
@(Html.Kendo().Grid< >()
.Name("InnerGrid")
.Columns(columns =>
{
....
})
.ToolBar(toolbar =>
{
toolbar.Create();
})
.DataSource(ds => ds
.Ajax()
....
.Read(r => r.Action(" ", " ").Data("getId"))
.Create(c => c.Action(" ", " ").Data("getId"))
)
.Events(e => e.Edit("innerGridEditEvent"))
)
I'm keeping the required Id as a hidden field, and the getId
event returns it.
function getHeadId(e) {
var id = $("#Id").val();
return { Id: id };
}
....
@Html.HiddenFor(x => x.Id)
innerGridEditEvent
function. It's currently using hard-coded value. – Akbari