I have a Telerik Grid for asp.net MVC 4 using Kendo 2014.
The grid has a 1 foreign key and I am using the foreign key template.
The Grid is working properly as far as CRUD operations, however, the GridData source is not getting updated. Consequently when trying to use the new updated values from the grid.dataSource (visible in the grid) I am getting the old values:
I have tried to update the datasource but am not able to get any of the prescribed datasource events events triggered other than events.change which is not specific enough.
Here is my Grid:
@(Html.Kendo().Grid<
PMTWebReconcile.Models.ProcEquipViewModel
>()
.Name("ProcEqGrid")
//.HtmlAttributes(new { style = "height: 480px; margin-left: 260px" })
.Events(events => events.Edit("onEdit"))//.Events(events => events.Change("onChange"))
.Columns(columns =>
{
columns.Bound(p => p.peqID).Width(20).Title("ID");
columns.Bound(p => p.peqName).Width(120).Title("Name");
columns.Bound(p => p.peqTag).Width(120).Title("Tag");
columns.Bound(p => p.peqDescription).Width(200).Title("Description");
columns.ForeignKey(p => p.eqtID, (System.Collections.IEnumerable)ViewData["EqptTypes"], "TypeID", "Type").Title("Eqpt Type").Width(200);
//columns.Bound(p => p.eqtID).Width(120).ClientTemplate("<
span
tabindex
=
'0'
class
=
'k-widget k-dropdown k-header'
unselectable
=
'on'
><
span
class
=
'k-dropdown-wrap k-state-default'
unselectable
=
'on'
><
span
class
=
'k-input'
unselectable
=
'on'
>Select Type</
span
><
span
class
=
'k-select'
><
span
class
=
'k-icon k-i-arrow-s'
>select</
span
></
span
></
span
><
input
name
=
'Type'
id
=
'Type'
style
=
'display: none;'
type
=
'text'
data-role
=
'dropdownlist'
></
span
>");
columns.Bound(p => p.peqID).Width(10).Title("Edit Sizes")
.ClientTemplate("<
button
type
=
'button'
onclick=\"EditProcEquipment(this);\"
text
=
'text'
class
=
'k-button k-button-icontext k-grid-edit'
style
=
'min-width: 30px; min-height: 25px; height: 25px; padding-top: 0; padding-right: 0;'
><
span
class
=
'k-icon k-edit'
></
button
>");
columns.Bound(p => p.peqActive).Width(30);
columns.Command(commands =>
commands.Edit().HtmlAttributes(new { style = "min-width:64px;width:80px" });
//commands.Delete().ButtonType(GridButtonType.Image);
}).Width(200);
})
.ToolBar(toolbar => { toolbar.Create(); toolbar.Save(); }) // toolbar.Save(); })
//.ToolBar(toolBar => toolBar.Template("<
a
class
=
'k-button k-button-icontext k-grid-add'
href
=
'#'
onlick
=
'customCreateCmd()'
>Add new record</
a
>"))
.HtmlAttributes(new { style = "veritcal-align:top" })
.Selectable(s => s.Mode(GridSelectionMode.Single))
//.Selectable(s => s.Mode(GridSelectionMode.Multiple))
//.Editable(editable => editable.Mode(GridEditMode.InLine)) // Use inline editing mode.
.Editable(editable => editable.Mode(GridEditMode.InCell))
.Pageable()
.Sortable()
.Filterable()
.DataSource(dataSource => dataSource
.Ajax()
.Batch(true)
.ServerOperation(false)
.Events(events => events.Error("errorHandler").Sync("onSync").RequestEnd("onRequestEnd"))//.Sync("sync_handler"))
//.Events(events => events.RequestEnd("onRequestEnd"))
//.Events(events => events.Change("onChange"))
//.Events(events => events.Push("onPush"))
//.Events(events => events.Edit("onEdit"))
.AutoSync(true)
.Model(model =>
{
model.Id(p => p.peqID); // Specify the property which is the unique identifier of the model.
model.Field(p => p.peqID).Editable(false); // Make the ProductID property not editable.
//model.Field(p => p.Type).DefaultValue(new PMTWebReconcile.Models.EquipTypeViewModel());
model.Field(p => p.eqtID).DefaultValue(16);
model.Field(p => p.plsID);//need to come from treeview selector
//model.Field(p => p.plsID).DefaultValue(Html.Kendo().TreeView("tvPH").select());
})
.Read(read => read.Action("ForeignKeyColumn_Read", "PlantHierArchy", new { plsID = (subUnitID) }))
.Create(create => create.Action("ForeignKeyColumn_Create", "PlantHierArchy"))
.Update(update => update.Action("ForeignKeyColumn_Update", "PlantHierArchy").Type(HttpVerbs.Post).Data("UpdateHandler"))
)
//.ClientDetailTemplateId
)
And my corresponding Update and Insert which are updating the Database Successfully.
[AcceptVerbs(HttpVerbs.Post)]
public
ActionResult ForeignKeyColumn_Create([DataSourceRequest] DataSourceRequest request,
[Bind(Prefix =
"models"
)]IEnumerable<ProcEquipViewModel> procEqs)
{
var results =
new
List<ProcEquipViewModel>();
if
(procEqs !=
null
&& ModelState.IsValid)
{
foreach
(var proc
in
procEqs)
{
CreateProcEquip(proc);
results.Add(proc);
}
}
return
Json(results.ToDataSourceResult(request, ModelState));
}
[AcceptVerbs(HttpVerbs.Post)]
public
ActionResult ForeignKeyColumn_Update([DataSourceRequest] DataSourceRequest request,
[Bind(Prefix =
"models"
)]IEnumerable<ProcEquipViewModel> procEqs)
{
if
(procEqs !=
null
&& ModelState.IsValid)
{
foreach
(var proc
in
procEqs)
{
//productService.Update(product);
UpdateProcEquip(proc);
}
}
DataSourceResult DSR = procEqs.ToDataSourceResult(request, ModelState);
JsonResult JR = Json(DSR);
return
JR;
}
How can I update my data source?
additionally it would also be nice to be able to capture and update other update items but The grid.datasource is the most important.