Kendo Grid编辑事件处理程序不更新行

时间:2020-06-10 03:55:18

标签: kendo-ui telerik kendo-grid

使用内联编辑将新项目添加到Kendo网格时,ContractID数据源将由选定的OrgID过滤。添加一行后,OrgID列将不再可编辑(使用isOrgEditable()进行设置),而ContractID则是可编辑的。不幸的是,级联然后无法用于编辑,并且ContractID的数据源未过滤。

要解决该问题,我订阅了编辑事件(data-edit="setContractsDataSource")并手动过滤数据源。那行得通,但是“更新”按钮什么也不做,并且编辑丢失。

<div id="grid">
    <div class="k-content wide">
        <div>
            <div data-role="grid"
                 data-editable="inline"
                 data-edit="setContractsDataSource"
                 data-toolbar="[{ name: 'create', text: 'Add Item' }]"
                 data-columns='[
                 { field: "OrgID", title: "Company", editable: isOrgEditable, editor: orgDropDownEditor, template: "#: lookupForOrg(organisationID) #" },
                 { field: "ContractID", title: "Contract", editor: contractsDropDownEditor, template: "#: lookupForContract(ContractID) #" },
                 { command: ["edit", "destroy"], width: "220px" }
            ]'
            data-sortable="true"
            data-pageable="true"
            data-filterable="true"
            data-bind="source: items"></div>
        </div>
    </div>
</div>

1 个答案:

答案 0 :(得分:0)

通常,我在写问题时就解决了这个问题。供以后参考,之所以不进行更新是因为未从事件处理程序中返回true

function setContractsDataSource(e) {
    let orgID = e.model ? e.model.OrgID : this.dataItem().OrgID;
    if (orgID) {
        $("#contracts").data("kendoDropDownList").setDataSource(contractsData.filter(elt => elt.ContractorID == orgID));
    }
    return true; // fixed it
}

随后确定该列仅在它已经包含一个值的情况下才会更新,即如果以前为空,则新值将不会保存。 This telerik forum post帮助解决了该问题。合同栏的编辑器需要valuePrimitive: true

function contractsDropDownEditor(container, options) {
    $('<input id="contracts" name="' + options.field + '"/>')
        .appendTo(container)
        .kendoDropDownList({
            autoBind: false,
            dataTextField: "ContractNo",
            dataValueField: "ContractID",
            dataSource: contractsData,
            optionLabel: "Select contract...",
            valuePrimitive: true
        });
}
相关问题