
function expandAndSelectNode(id, treeViewName) { // get the Kendo TreeView widget by it's ID given by treeviewName var treeView = $(treeViewName).data('kendoTreeView'); // find node with data-id = id var item = $(treeViewName).find("li[data-id='" + id + "']").find(".k-in"); // expand all parent nodes $(item).parentsUntil('.k-treeview').filter('.k-item').each( function (index, element) { $(treeViewName).data('kendoTreeView').expand($(this)); } ); // get DataSourceItem by given id var nodeDataItem = treeView.dataSource.get(id); //get node within treeview widget by uid var node = treeView.findByUid(nodeDataItem.uid); $(treeView).select(node); //treeView.select(".k-item:last");}columns.Bound(e => e.BookValue).Title("Book Value ($)") .ClientFooterTemplate("<div class=aright>#=sum#</div>").Format("{0:N}")public class BranchesViewModel{ public IQueryable<BranchViewModel> Branches { get; set; } public IEnumerable<RegionViewModel> Regions { get; set; }}public class BranchViewModel{ [Editable(false, AllowInitialValue = true)] [Required] [Display(Name="Id")] [HiddenInput(DisplayValue = false)] public int BranchId { get; set; } [Display(Name="GL Code", Order=2)] [Required] public string GLCode { get; set; } [Display(Name="Region", Order=3)] [Required] [UIHint("RegionForeignKey")] public int RegionId { get; set; } [Display(Name="Branch Name", Order=1)] [Required] public string BranchName { get; set; }}public class RegionViewModel{ public int RegionId { get; set; } public string RegionName { get; set; }}<h2>Branches</h2>@(Html.Kendo().Grid<BranchViewModel>() .Name("Branch") .Columns(col => { col.Bound(m => m.BranchName); col.Bound(m => m.GLCode).Width(200); col.ForeignKey(m => m.RegionId, Model.Regions, "RegionId", "RegionName").Width(180); col.Command(cmd => { cmd.Edit(); cmd.Destroy(); }).Width(180); }) .ToolBar(toolBar => toolBar.Create().Text("New Branch")) .Editable(edit => { edit.Mode(GridEditMode.InLine); edit.DisplayDeleteConfirmation(true); }) .Sortable() .DataSource(dataSource => dataSource .Ajax() .Batch(true) .ServerOperation(false) .Events(events => events.Error("errorHandler")) .Model(model => model.Id(b => b.BranchId)) .Read(read => read.Action("Branch_Read", "Branch")) .Create(create => create.Action("Branch_Create", "Branch")) .Update(update => update.Action("Branch_Update", "Branch")) .Destroy(destroy => destroy.Action("Branch_Delete", "Branch")) ))@model int@(Html.Kendo().DropDownListFor(m => m) .BindTo((SelectList)ViewData[ViewData.TemplateInfo.GetFullHtmlFieldName("") + "_Data"]))public ActionResult Index(){ var model = new BranchesViewModel { Branches = _branchRepository.Get().Select( b => new BranchViewModel { BranchId = b.Id, GLCode = b.GLCode, BranchName = b.BranchName, RegionId = b.RegionId } ), Regions = _regionRepository.Get().Select( r => new RegionViewModel { RegionId = r.Id, RegionName = r.RegionName } ).ToList() }; return View(model);}// Ajax for branchespublic ActionResult Branch_Read([DataSourceRequest] DataSourceRequest request){ var branches = _branchRepository.Get().Select( b => new BranchViewModel { BranchId = b.Id, GLCode = b.GLCode, BranchName = b.BranchName, RegionId = b.RegionId } ); return Json(branches.ToDataSourceResult(request));}I am using an editor template to provide custom behavior in my grid when a user edits a record. The editor template .cshtml file is as follows:
@model string
@Html.TextBoxFor(s => s, new { id ="gradingSubItemGrade", @class="k-textbox" })
<script type="text/javascript">
$(document).ready(function () {
$('#gradingSubItemGrade').bind('keypress', function (e) {
if (e.keyCode == 13) {
var barcode = e.currentTarget.value;
GetJSON('/API/CoinReferenceInformation/ByBarcode?barcode=' + barcode,
function (data) {
$('#gradingSubItemGrade').val(data.Grade + data.GradeNumber);
},
function () { });
}
});
})
</script>
As you can probably see from the code sample, I am trying to send the text of the TextBox to a service (when [Enter] is pressed), then, upon receiving a response, override it with the results.
This almost works...the response comes back correctly, and the results are displayed in the TextBox. However, what is saved is what the user entered, not what is returned by the service.
Are there additional steps I need to do to notify the grid that the text has changed?
@(Html.Kendo().Grid<DigiBob.AppServices.ViewModels.Governance.Duties.AdhocTaskViewModel>() .Name("Grid") .Columns(columns => { columns.Bound(p => p.ShortDescription).Width(50); columns.Command(command => { command.Edit(); command.Destroy(); }).Width(160); }) .ToolBar(toolbar => { toolbar.Create(); }) .Editable(ed=>ed.Mode(GridEditMode.PopUp).TemplateName("AdhocTask")) .Pageable() .Sortable() .Scrollable() .Filterable() .DataSource(dataSource => dataSource .Ajax() .PageSize(20) .Events(events => events.Error("error_handler")) .Model(model => model.Id(c => c.ID)) .Create(update => update.Action("CreateAdhocTask", "Home")) .Read(read => read.Action("GetAllAdhocTasks", "Home")) .Update(update => update.Action("UpdateAdhocTask", "Home")) .Destroy(update => update.Action("DestroyAdhocTask", "Home")) ) )[AcceptVerbs(HttpVerbs.Post)] public ActionResult CreateAdhocTask([DataSourceRequest] DataSourceRequest request, AdhocTaskViewModel item) { if (item != null && ModelState.IsValid) { _adhocTaskRepository = new AdhocTaskRepository(_context); AdhocTask target = new AdhocTask(); target.ShortDescription = item.ShortDescription; _adhocTaskRepository.Insert(target); _adhocTaskRepository.Save(); item.ID = target.ID; } return Json(new[] { item }.ToDataSourceResult(request, ModelState)); }