This question is locked. New answers and comments are not allowed.
Hi all
I'm experiencing an issue when trying to add rows in a second-level grid using InCell editing.
After doing the batch-update, the grid keeps new rows in their edited-state. This makes the user doubt whether the update actually took place and means that any further edits result in inserting the row again.
This is my code.
The grid:
The auto-expand script I'm using onRowDatabound:
The controller update and bind functions:
Any hints on what I'm doing wrong here will be greatly appreciated.
TIA
I'm experiencing an issue when trying to add rows in a second-level grid using InCell editing.
After doing the batch-update, the grid keeps new rows in their edited-state. This makes the user doubt whether the update actually took place and means that any further edits result in inserting the row again.
This is my code.
The grid:
@(Html.Telerik().Grid<PriceAdjustmentsViewModel>() .Name("AgeAdjustGrid") .DataKeys(keys => keys.Add(o => o.Id)) .DataBinding(bind => bind.Ajax() .Select("BindPriceAdjustments", "Adjustments", new { SeasonId = Model.Id }) .Update("UpdatePriceAdjustment", "Adjustments") .Delete("DeletePriceAdjustment", "Adjustments") ) .Columns(columns => { columns.Bound(o => o.Name).Width(360); columns.Command(commands => { commands.Edit().ButtonType(GridButtonType.Image); commands.Delete().ButtonType(GridButtonType.Image); }); }) .Footer(false) .ClientEvents(events => events.OnRowDataBound("ExpandRow")) .DetailView(detail => detail.ClientTemplate( Html.Telerik().Grid<AgeIntervalsViewModel>() .Name("AgeInterval<#= Id #>") .DataKeys(keys => keys.Add(o => o.Id)) .Editable(editing => editing.Mode(GridEditMode.InCell)) .DataBinding(bind => bind.Ajax() .Select("BindAgeAdjustments", "Adjustments", new { PriceAdjustmentId = "<#= Id #>" }) .Update("UpdateAgeAdjustments", "Adjustments", new { PriceAdjustmentId = "<#= Id #>" }) ) .ToolBar(commands => { commands.Insert().ButtonType(GridButtonType.Image); commands.SubmitChanges().ButtonType(GridButtonType.Image); }) .Columns(subcolumns => { subcolumns.Bound(o => o.AgeFrom); subcolumns.Bound(o => o.AgeTo); subcolumns.Bound(o => o.Amount); subcolumns.Bound(o => o.Auto).ClientTemplate("<#= Auto ? 'Auto' : 'Manuel' #>"); subcolumns.Command(command => command.Delete().ButtonType(GridButtonType.Image)); }) .Footer(false) .ToHtmlString() )))The auto-expand script I'm using onRowDatabound:
<script type="text/javascript"> function ExpandRow(e) { $("#AgeAdjustGrid").data("tGrid").expandRow(e.row); }</script>The controller update and bind functions:
[GridAction]public ActionResult BindAgeAdjustments(int PriceAdjustmentId){ ProTravelDB Db = MyDatabase.GetProTravelDB(); PriceAdjustmentsViewModel PA = new PriceAdjustmentsViewModel((from PAs in Db.PriceAdjustments where PAs.Id == PriceAdjustmentId select PAs).First()); return View(new GridModel(PA.AgeIntervals));}[GridAction]public ActionResult UpdateAgeAdjustments(int PriceAdjustmentId, [Bind(Prefix = "inserted")]IEnumerable<AgeIntervalsViewModel> inserted, [Bind(Prefix = "updated")]IEnumerable<AgeIntervalsViewModel> updated, [Bind(Prefix = "deleted")]IEnumerable<AgeIntervalsViewModel> deleted){ ProTravelDB Db = MyDatabase.GetProTravelDB(); if (inserted != null) { foreach (AgeIntervalsViewModel PA in inserted) { PriceAdjustmentAgeIntervals interval = new PriceAdjustmentAgeIntervals(); interval.AgeFrom = PA.AgeFrom; interval.AgeTo = PA.AgeTo; interval.Amount = PA.Amount; interval.Auto = PA.Auto; interval.PriceAdjustmentId = PriceAdjustmentId; Db.Add(interval); Db.SaveChanges(); } } if (updated != null) { foreach (AgeIntervalsViewModel PA in updated) { PriceAdjustmentAgeIntervals PaAIToUpdate = (from PAAIs in Db.PriceAdjustmentAgeIntervals where PAAIs.Id == PA.Id select PAAIs).First(); PaAIToUpdate.AgeFrom = PA.AgeFrom; PaAIToUpdate.AgeTo = PA.AgeTo; PaAIToUpdate.Amount = PA.Amount; PaAIToUpdate.Auto = PA.Auto; Db.SaveChanges(); } } if (deleted != null) { foreach (AgeIntervalsViewModel PA in deleted) { PriceAdjustmentAgeIntervals PaAIToDelete = (from PAAIs in Db.PriceAdjustmentAgeIntervals where PAAIs.Id == PA.Id select PAAIs).First(); Db.Delete(PaAIToDelete); Db.SaveChanges(); } } return View(new GridModel(new PriceAdjustmentsViewModel((from PAs in Db.PriceAdjustments where PAs.Id == PriceAdjustmentId select PAs).First()).AgeIntervals));}Any hints on what I'm doing wrong here will be greatly appreciated.
TIA