I have a Kendo grid that is enabled for InCell editing. The Grid is also configured for CURD operation.
So whenever there is a change in the grid row. The user has to click SaveChanges command button to save changes. The grid will post collection of row model to the server.
@(Html.Kendo().Grid<mymodel>()
.Name("mygrid")
.Columns(columns =>
{
//columns here
columns.Command(command => command.Destroy()).Width(100);
})
.ToolBar(toolbar =>
{
toolbar.Create();
toolbar.Save();
})
.Editable(editable => editable.Mode(GridEditMode.InCell))
.Pageable()
.Navigatable()
.Sortable()
.Scrollable()
.Filterable()
.AutoBind(true)
.DataSource(dataSource => dataSource
.Ajax()
.Batch(true)
.PageSize(20)
.ServerOperation(false)
.Model(model =>
{
model.Id("Id");
var f = model.Field("Id", typeof(int));
f.Editable(false);
})
.Model(model =>
{
model.Id("Id");
var f = model.Field("Id", typeof(int));
f.Editable(false);
})
.Create("Create", "Test")
.Read("Get", "Test")
.Update("Update", "Test")
.Destroy("Delete", "Test")
))
When user clicks SaveChanges, I want to modify the row model before posting to the server.
Grid has SaveChanges event which get fire every time user click SaveChanges
$(function(){
var kendoGrid = $("#mygrid").getKendoGrid();
kendoGrid.bind("saveChanges", function (e) {
var datasource = kendoGrid.dataSource;
// how do I update data before posting it to the server here
});
How do I update model that is about to post to server? Is SaveChanges event the correct event to handle this scenario?
I im not familiar with kendo for asp.net so i cannot give you exact answer, but usually you can intercept, or add, or modify data in
parameterMapbefore sending, for example:You can check this official example, i only changed
ProductNameon first object that will be sent on update click:Batch update intercept before sending
I hope you can salvage something from this, gl!