如果将过滤器应用于任何列,则无法将新对象添加到KendoUI网格 [英] Can't add new object to KendoUI grid if filter is applied to any column

查看:95
本文介绍了如果将过滤器应用于任何列,则无法将新对象添加到KendoUI网格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在弹出式编辑模式下使用KendoUI网格.将过滤器应用于任何列之后,将无法正确添加新对象.多次按添加​​按钮不会显示编辑弹出窗口.但是清除筛选器后,空对象将显示在网格中. 有什么解决方法吗?

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?

推荐答案

我找到了一种解决方法.代替标准的添加按钮,使用工具栏模板,在该模板中添加带有自定义处理程序触发网格添加的链接添加".在该处理程序中,检查是否在网格上使用了过滤,如果是,则将当前过滤存储到var中并删除过滤.还绑定到网格保存"和取消"事件处理程序,这些处理程序将在添加新对象(或取消)后应用以前的过滤.

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.

这篇关于如果将过滤器应用于任何列,则无法将新对象添加到KendoUI网格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆