Zhorian Zhorian - 1 year ago 127
Javascript Question

Updating model on kendo grid

So I have the below kendo grid on my view. At certain points an ajax call will update the Model.Id used in the model. The problem is when the Model.Id is updated the model on the grid isn't. Is there any way to update this?

@(Html.Kendo().Grid<OfferStatementVm>().Name("gridStatementList")
.Columns(columns => {
columns.Bound(c => c.Statement).Title("STATEMENT");
columns.Command(command =>
{
command.Edit();
command.Custom("custom-delete").Click("statementList_onDelete").Text("DELETE");
}).Title("Actions").Width(165);
})
.ToolBar(toolbar => toolbar.Create().Text("Add Statement"))
.NoRecords("No Statements Found")
.DataSource(dataSource => dataSource
.Ajax()
.Model(model => {
model.Id(p => p.Id);
model.Field(p => p.OfferId).DefaultValue(Model.Id);
})
.Read(read => read.Action("GetStatementList", "OffersCreateOrUpdate", new { Area = "Offers"})
.Data("offerApp.getStatementListSearch"))
.Sort(x => x.Add("Id"))

.Create(create => create.Action("InsertStatement", "OffersCreateOrUpdate", new { Area = "Offers" })
.Data("offerApp.getAntiForgeryToken('#offersCreateOrUpdateForm')"))

.Update(update => update.Action("UpdateStatement", "OffersCreateOrUpdate", new { Area = "Offers" })
.Data("offerApp.getAntiForgeryToken('#offersCreateOrUpdateForm')"))

.Events(events => {
events.Error("offerApp.statementList_onError");
events.Sync("offerApp.refreshStatementList");
}))
.Events(events => events.DataBound("offerApp.statementList_onDataBound")))


Cheers,

Z

Answer Source

I managed to get around this by moving the grid into a partial view and rendering it once I had a valid Model.Id.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download