Hi Telerik Team,
I have a KendoGrid defined as below:
@(Html.Kendo().Grid(Model.ExceptionList) .Name("ThesholdGrid") .Columns(columns => { columns.Bound(p => p.StoreID).Title("StoreID").Width(100); columns.Bound(p => p.StoreName).Title("Store Name"); columns.Bound(p => p.StockCode).Title("StockCode").Width(125).EditorTemplateName("StockCodeAutoComplete"); columns.Bound(p => p.ItemDesc).Title("Item Desc"); columns.Bound(p => p.NoThres).Title("No Stock Threshold"); columns.Bound(p => p.LowThres).Title("Low Stock Threshold"); columns.Command(cmd => cmd.Destroy()).Width(150); }) .ToolBar(toolbar => { toolbar.Create(); toolbar.Save(); }) .Editable(editable => editable.Mode(GridEditMode.InCell)) .Sortable() .Resizable(resizable => resizable.Columns(true)) .DataSource(dataSource => dataSource .Ajax() .ServerOperation(false) .Model(model => { model.Id(p => new { p.StoreID, p.StockCode }); model.Field(p => p.StoreName).Editable(false); model.Field(p => p.ItemDesc).Editable(false); }) .Update("UpdateInvTransReview", "Inventory") ))The template for the AutoComplete:
@(Html.Kendo().AutoCompleteFor(m=>m) .DataTextField("StockCode") .DataSource(source => { source.Read(read => { read.Action("GetStockCodes", "Inventory").Data(@"function () { return { keyword: ? };}"); }); }) .HtmlAttributes(new { style = "width:100%" }) .Filter("contains") .MinLength(3) .Height(400) .FooterTemplate("Total <strong>#: instance.dataSource.total() #</strong> items found") .Template("#:data.CombinedDesc#"))And the controller for the AutoComplete:
[HttpGet]public JsonResult GetStockCodes(string keyword){ if (string.IsNullOrEmpty(keyword)) return Json(new List<StockCodeDesc>(), JsonRequestBehavior.AllowGet); var stockCodes = _stockcodeClient.SearchStockCode(keyword); stockCodes.ForEach(sc => sc.CombinedDesc = sc.Desc + " (" + sc.StockCode + ")"); return Json(stockCodes, JsonRequestBehavior.AllowGet);}The model for the AutoComplete:
public class StockCodeDesc{ public string StockCode { get; set; } public string Desc { get; set; } public string CombinedDesc { get; set; } <other fields>}The grid takes data from the model and has inline editing enabled. I would like to have the StockCode field as an AutoComplete and when user selects an item, it will populate the ItemDesc field as well.
From the model you may have guessed that the StockCode field is the text of the AutoComplete, the CombinedDesc is used as template for easier viewing and the Desc is meant to populate the column ItemDesc of the KendoGrid.
My first question is what to put as the "keyword" mapping in the definition of the AutoComplete. I've tried to user parameterMap of the Transport like:
parameterMap: function (data, action) { return { keyword: data.filter.filters[0].value };}
But the filter is always null.
My second question is how to populate the other field of the grid based on what user selects from the AutoComplete. I figure I should approach this using select event of the AutoComplete but have found no working example.
Thank you,
Michael.