在ADD / EDIT之后,Kendo Dropdown Value不会更新GRID

时间:2015-06-19 07:40:25

标签: javascript jquery asp.net-mvc kendo-grid

我使用以下代码用于Kendo Grid。我正在使用六个下拉菜单和一个文本框输入字段。它非常适用于添加,编辑和放大删除操作并将记录反映到数据库中,但唯一的问题是在添加和编辑操作之后,下拉字段的值不显示网格而是值进入数据库。

$("#riskassessment").kendoGrid({
        dataSource: {
            transport: {
                read: { url: serverUrl + "/RiskAssessment/GetRiskAssessment", type: "GET", dataType: 'json', cache: false },
                update: {
                    url: serverUrl + "/RiskAssessment/PostRiskAssessmentEdit",
                    type: "POST"                    
                },
                create: {
                    url: serverUrl + "/RiskAssessment/PostRiskAssessmentAdd",
                    type: "POST"                   
                },
                destroy: { url: serverUrl + "/RiskAssessment/DeleteRiskAssessment", type: "POST", cache: false }               
            },
            schema: {
                model: {
                    id: "RiskAssessmentConfigId",
                    fields: {
                        RiskAssessmentConfigId: { editable: false, nullable: false },
                        ComponentId: { editable: true, nullable: false, validation: { required: true } },
                        XCHKZEROId: { editable: true, nullable: false, validation: { required: true } },
                        YieldId: { editable: true, nullable: false, validation: { required: true } },
                        CVALBEId: { editable: true, nullable: false, validation: { required: true } },
                        CVALFQAID: { editable: true, nullable: false, validation: { required: true } },
                        RiskId: { editable: true, nullable: false, validation: { required: true } }
                    }
                }
            },
            sort: [{ field: "ComponentId", dir: "asc" }],
            pageSize: 5
        },
        columns: [
                { field: "ComponentId", title: "Component", editor: ComponentDropDownEditor, width: "150px", template: "#= GetGeneralDDLabelName(ComponentId) #" },
                { field: "YieldId", title: "Yield", editor: YieldDownEditor, width: "150px", template: "#= GetGeneralDDLabelName(YieldId) #" },
                { field: "CVALBEId", title: "CVAL BE", editor: CVALBEDropDownEditor, width: "150px", template: "#= GetGeneralDDLabelName(CVALBEId) #" },
                { field: "CVALFQAID", title: "CVAL FQA", editor: CVALFQADropDownEditor, width: "150px", template: "#= GetGeneralDDLabelName(CVALFQAID) #" },
                { field: "XCHKZEROId", title: "XCHKZERO", editor: XCHKZERODropDownEditor, width: "150px", template: "#= GetGeneralDDLabelName(XCHKZEROId) #" },
                { field: "RiskId", title: "Risk", editor: RiskDropDownEditor, width: "150px", template: "#= GetRiskDDLabelName(RiskId) #" },
                { field: "Remarks", title: "Remarks" },
                { command: ["edit", "destroy"], title: " ", width: "180px" }],
        editable: "popup",
        pageable: true,
        sortable: true,
        toolbar: ["create"],
        change: onChange,
        RequestEnd: onGridDataSourceRequestEnd
    });

保存或编辑记录后显示如下。

enter image description here

任何人请帮我解决这个问题。

我还添加了RequestEnd事件来刷新网格,但事件没有触发。

function onGridDataSourceRequestEnd(e) {
    alert(e.type);
    if (e.type == "update") {
        $("#riskassessment").data("kendoGrid").dataSource.read();
    }
}

2 个答案:

答案 0 :(得分:0)

内部字段而不是提供

template: "#= GetGeneralDDLabelName(YieldId) #"

尝试给予

template: "#=YieldId#"

来到RequestEnd语法错误

requestEnd:function(e)

答案 1 :(得分:0)

我也遇到了同样的问题。

以下是我对问题和解决方案的理解:

基本上,下拉列表编辑器是一个从外部数据源构建下拉列表的函数。所以,它工作正常。但是,要使模板定义以(field.property)格式工作,服务器必须将该值作为此字段的类返回,而不是简单文本。

因此,您可以从服务器端服务返回以下格式:

{"ComponentId":{"id":"YOURID","name":"YORNAME"}}

更进一步,你可以使用对象

template: "#= ComponentId.name #"  //or "#= GetGeneralDDLabelName(ComponentId.name) #" according your code