簡體   English   中英

在 Javascript 調用中更新劍道網格列(外鍵)

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

所以我是 MVC 中劍道控件的新手。

我有以下 .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")

所以在我的更改事件中,我在 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();                                               }            
            });
        }
    };

這些列使用我們提交的最新數據 hwen 更新得很好,但帶有外鍵的列沒有在網格下拉列表中反映它們的值。 它顯示了與之前相同的數據。

有什么解決辦法嗎?

data、data1 和 data2 應該是 Enumerable 類型並包含鍵和值然后你應該在 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