简体   繁体   English

单元格离开编辑模式时,批处理网格单元格将从DropDownList中获取DataValueField

[英]Batch Grid cell takes DataValueField from DropDownList when cell leaves edit mode

What I want to do is display text for a company name in the drop down AND the cell (when it's not being edited), but have the ID of the company be the data that is passed back to the server when "Save" is clicked. 我想要做的是在下拉列表和单元格中显示公司名称的文本(当未编辑时),但是要使公司的ID为单击“保存”时传递回服务器的数据。

Everything works perfectly, except that when I click on the next cell to continue my edits (which causes the cell with the DDL to leave edit mode), the read only cell in its place displays the ID instead of the Company's name. 一切工作正常,除了当我单击下一个单元格以继续编辑(这会导致具有DDL的单元格退出编辑模式)时,只读单元格代替其位置显示ID而不是公司名称。

This picture illustrates what I mean: 这张图片说明了我的意思: 在此处输入图片说明

Does anyone know a way to fix this or a different way to achieve the functionality that I need? 有谁知道解决此问题的方法或实现我所需功能的另一种方法?

Editor Template 编辑器范本

@(Html.Kendo().DropDownList()
.Name("Company")
.DataTextField("Name")
.DataValueField("EnterpriseID")
.BindTo((IEnumerable<BlueGrace.BlueShip.Business.Enterprise.EnterpriseChildListingItem>)ViewBag.RefCarrierLiabilityEnterpriseListing))

Controller (ViewBag population) 控制器(ViewBag人口)

var enterpriseListing = Business.Enterprise.EnterpriseChildListing.Get(false, customIdentity.EnterpriseID, false).ToList();
        ViewBag.RefCarrierLiabilityEnterpriseListing = enterpriseListing;

View 视图

    @(Html.Kendo().Grid(Model.GlobalDictionary.RefCarrierLiabilityModels)
        .Name("CarrierLiabilityDictionaryGrid")
    .Columns(columns =>
    {
        columns.Bound(item => item.CarrierName)
            .EditorTemplateName("RefCarrierListing").Width(250);
        columns.Bound(item => item.Company)
            .EditorTemplateName("RefCarrierLiabilityEnterpriseListing");
        columns.Bound(item => item.MaxLiability)
            .EditorTemplateName("RefCarrierLiabilityMaxLiability");
        columns.Bound(item => item.IsValueOfGoodsMaxLiability);
        columns.Command(command =>
        {
            command.Destroy();
        }).Width(100);
    })
    .ToolBar(toolbar =>
    {
        toolbar.Create();
        toolbar.Save();
    })
    .Editable(editable => editable.Mode(GridEditMode.InCell).CreateAt(GridInsertRowPosition.Top))
    .Pageable()
    .Sortable()
    .Scrollable()
    .Filterable()
    .Resizable(resize => resize.Columns(true))
    .Reorderable(reorder => reorder.Columns(true))
    .DataSource(dataSource => dataSource
        .Ajax()
        .Batch(true)
        .ServerOperation(false)
        .Model(model =>
        {
            model.Id(i => i.RefCarrierLiabilityID);
            model.Id(i => i.RefCarrierID);
        })
        .Read(read => read.Action("GetCarrierLiabilities", "Dictionary"))
        .Create(create => create.Action("CreateCarrierLiabilities", "Dictionary"))
        .Update(update => update.Action("UpdateCarrierLiabilities", "Dictionary"))
        .Destroy(delete => delete.Action("DeleteCarrierLiabilities", "Dictionary"))
    )
)

The Grid provides a functionality called ForeignKey column which what you need I guess. 网格提供了一个称为ForeignKey列的功能,我猜这是您需要的。 Check this demo (change the source to .cshtml to see all you need to do). 检查此演示(将源更改为.cshtml以查看您需要做的一切)。

columns.ForeignKey(p => p.EmployeeID, (System.Collections.IEnumerable)ViewData["employees"], "EmployeeID", "EmployeeName");

http://demos.kendoui.com/web/grid/foreignkeycolumn.html http://demos.kendoui.c​​om/web/grid/foreignkeycolumn.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM