简体   繁体   English

在 Javascript 调用中更新剑道网格列(外键)

[英]Update Kendo Grid Column(Foreign Key) on Javascript Call

So i am new to kendo controlles in MVC.所以我是 MVC 中剑道控件的新手。

I have below .cshtml file.我有以下 .cshtml 文件。

 @(Html.Kendo().Grid<AssetDeprGroupViewModel>()
        .Name("AssetDeprGrid")
        .Columns(c =>
        {                
            c.Bound(p => p.AssetDeprGroup).Title("Depr Group").HeaderHtmlAttributes(new { style = "text-align: center" }).ClientTemplate("<span title='#=data.AssetDeprGroup#'>#=data.AssetDeprGroup#</span>").Width(85);
            c.ForeignKey(p => p.AssetDeprClass, data2).Title("Class").HeaderHtmlAttributes(new { style = "text-align: center" }).Width(53);                                    
            c.Group(gr => gr
            .Title("AMT").HeaderHtmlAttributes(new { style = "text-align: center" })
                .Columns(info =>
                {
                    info.ForeignKey(p => p.MethodAMT, data1).HeaderHtmlAttributes(new { style = "text-align: center" }).Title("Method").Format("{0:p0}").Width(41);
                    info.ForeignKey(p => p.ConventionAMT, data).HeaderHtmlAttributes(new { style = "text-align: center" }).Title("Convention").Width(41);
                    info.Bound(p => p.LifeAMT).HeaderHtmlAttributes(new { style = "text-align: center" }).Title("Life").Width(25);                    
                })
                );               
            c.Command(command =>
            {
                command.Edit(); command.Destroy();
            }).Visible(hasCRUDpermission)                                      
                .Width(55)
                .Title("Action")
                .HtmlAttributes(new { style = "text-align: center;" })
                .HeaderHtmlAttributes(new { style = "text-align: center;" });
        })

        .Editable(editable => editable.Mode(GridEditMode.InLine))
        .Scrollable()
        .DataSource(ds => ds
            .Ajax()
            .ServerOperation(true)
            .Events(e => e.Sync("sync_handler").Change("autoPopulate"))                                                
            .Read("GetAssetDeprGroups", "ProjectManagement")
            .Create("CreateAssetGroups", "ProjectManagement")
            .Update(update=>update.Action("UpdateAssetGroups", "ProjectManagement").Data("additionalInfo"))
            .Destroy("DeleteAssetGroups", "ProjectManagement")

So on my change event i am calling below javascript.所以在我的更改事件中,我在 javascript 下调用。

 function autoPopulate(e) {
        if (e.action == 'itemchange' && e.field == 'AssetDeprClass') {            
            //var grid = $("#AssetDeprGrid").data("kendoGrid");
            var assetClassUrl = "@Url.Content("~/ProjectManagement/GetAssetDeprClass")";
            var assetClass = $("#AssetDeprClass").val();
            $.ajax({
                url: assetClassUrl,
                type: "POST",
                data: { assetClass: assetClass },
                success :function(d) {                    
                    var classData = d.Data[0];                    

                    $("#LifeAMT").val(classData.LifeAMT).toString();
                    $("#MethodAMT").val(classData.MethodAMT).toString();
                   $("#ConventionAMT").val(classData.ConventionAMT).toString();                                               }            
            });
        }
    };

The columns are updating fine with the latest data hwen we submit but the columns with foreign key are not reflecting their value on grid dropdown.这些列使用我们提交的最新数据 hwen 更新得很好,但带有外键的列没有在网格下拉列表中反映它们的值。 It shows the same data as previous.它显示了与之前相同的数据。

Any solution?有什么解决办法吗?

data, data1 and data2 should be Enumerable type and include key and value then you should specify key and value in the ForeignKey column data、data1 和 data2 应该是 Enumerable 类型并包含键和值然后你应该在 ForeignKey 列中指定键和值

for example if MethodAMT is your foreignkey:例如,如果 MethodAMT 是您的外键:

info.ForeignKey(p => p.MethodAMT, data1 , "MeshodAMT" ,"MeshodAMTTitle").HeaderHtmlAttributes(new { style = "text-align: center" }).Title("Method").Format("{0:p0}").Width(41);

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

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