Can't add new object to KendoUI grid if filter is applied to any column

自古美人都是妖i 提交于 2020-04-30 07:47:16

问题


I use KendoUI grid with popup edit mode. After applying filter to any column it is not possible to add new object correctly. Pressing Add button many times does not show edit popup. But after clearing the filter empty objects are shown in the grid. Is there any workaround?


回答1:


I found a workaround. Instead of standard Add button use toolbar template in which add link "Add" with custom handler triggering grid add. In that handler check if filtering is used on grid and if so store current filtering to a var and remove filtering. Also bind to grid "save" and "cancel" events handlers which will apply previous filtering after adding new object (or cancelling).

    <kendo:grid-toolbarTemplate>
        <div>
            <a class="k-button k-button-icontext" onclick="addItemHandler()">Add</a>
    ...

    var gridFilter;

    function addItemHandler() {
        var table = $("#myGrid").data("kendoGrid");

        gridFilter = table.dataSource.filter();

        if (gridFilter) {
            table.dataSource.filter(null);
        }

        table.addRow();
    }

    function gridSavedHandler(e) {       
        restoreFilter(e.sender);
    }

    function gridEditCanceledHandler(e) {
        e.preventDefault();
        e.sender.cancelChanges();
        restoreFilter(e.sender);
    }

    function restoreFilter(table) {
        if (gridFilter) {
            table.dataSource.filter(gridFilter);
            gridFilter = null;
        }
    }

   $(document).ready(pageInitHandler);

   function pageInitHandler() {
       var table = $("#myGrid").data("kendoGrid");
       table.bind("save", gridSavedHandler);
       table.bind("cancel", gridEditCanceledHandler);
   }

Workaround is complicated one but really works.



来源:https://stackoverflow.com/questions/17840312/cant-add-new-object-to-kendoui-grid-if-filter-is-applied-to-any-column

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!