剑道:组合框在网格 - 选送组合框的附加数据组合框阅读() [英] Kendo : ComboBox in a grid - Sending additional data of selected combobox to combobox Read()

查看:149
本文介绍了剑道:组合框在网格 - 选送组合框的附加数据组合框阅读()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

ASP.NET MVC5

ASP.NET MVC5

我在电网组合框 (联编辑):

I have a combobox in a grid (InLine Edit):

columns.Bound(x=>x.AccountID).EditorTemplateName("MyTemplate")

其中, MyTemplate的是/共享

有上百万账户。

当我尝试编辑在组合框在网格中并选择一个新的值,该账户的ID,而不是名称出现。这是因为,当然帐户的名称不是立即在阅读()present左右。在 ComboBox.Datasource 我需要发送的额外的数据;该帐户ID。

When I try to edit the combo box in a grid and choose a new value, the ID of the Account, not the name, appears. This is because of course the name of the account is not immediately present so in the Read().Data() of the ComboBox.Datasource I need to send additional data; the AccountID.

我的组合框模板看起来是这样的:

My ComboBox Template looks like this:

.DataSource(source=>
   source.Read(read =>
      read.Action("ReadAccounts".....)
         .Data("HERE IS WHERE I NEED TO SEND THE ACCOUNT ID AS EXTRA DATA 
             WHEN THIS CBO TEMPLATE IS IN A GRID")

感谢您

推荐答案

下面是在的局部视图定义的组合框〜/查看/共享/ 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);
    }

与任何一款Ajax调用,在$ C $下将破发点,可能prevent从按预期执行的小部件。对于前。使用盒内编辑的同时单击要编辑的字段,如果放在 GetCombo断点组合框编辑模板将不能正确地默认为该值。

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.

这篇关于剑道:组合框在网格 - 选送组合框的附加数据组合框阅读()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆