Here's the Combo Box defined in a partial view in ~/Views/Shared/EditorTemplates/ComboBoxTemplate
@(Html.Kendo().ComboBox()
.Name("AcctName")//must match Field Name that is being edited
.HtmlAttributes(new { style = "width:250px" })
.DataTextField("AcctName")
.DataValueField("AcctCd")
.Filter(FilterType.StartsWith)
.AutoBind(true)
.MinLength(3)
.DataSource(source =>
{
source.Read(read =>
{
read.Action("GetCombo", "GridPost").Data("OnAdditionalData");
})
.ServerFiltering(true);
})
)
Here's the view and controller action
columns.Bound(x => x.AcctName).Title("Acct Name").EditorTemplateName("ComboBoxTemplate");
function OnAdditionalData() {
var entityGrid = $("#ProposalGridX").data("kendoGrid");
var selected = entityGrid.dataItem(entityGrid.select());
//if the id is off the Grid Row and not the ComboBox
//select the row and pull the fields
//selected.PropertyName
return {
text : $("#AcctName").data("kendoComboBox").text(),
val : $("#AcctName").data("kendoComboBox").value()
};
}
public JsonResult GetCombo(string text, string val)
{
List<PortfolioViewModel> model = new AUMBusiness().GetAum(DateTime.Now);
if (!string.IsNullOrEmpty(text))
{
model = model.Where(x => x.AcctName.StartsWith(text)).ToList();
}
return Json(model, JsonRequestBehavior.AllowGet);
}
Like with any Ajax calls, placing break points in the code might prevent the widget from performing as intended. For ex. using incell editing while clicking the Field to edit, if you place a breakpoint in GetCombo
the ComboBox editor template will not default correctly to that value.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…