简体   繁体   English

如何通过输入按键在kendo ui网格上触发过滤器事件?

[英]How to fire filter event on kendo ui grid by Enter keypress?

I use Kendo UI v2014.2.716 我使用Kendo UI v2014.2.716

I have a grid with paging,sorting,filtering by server side, and i enable filter row for my grid. 我有一个通过服务器端进行分页,排序,过滤的网格,并且为网格启用了过滤器行。

When i test this filter, i realized that: 当我测试此过滤器时,我意识到:

  • The filters fire when : 过滤器在以下情况下触发:
    • When input filter lost focus. 输入过滤器失去焦点时。
    • when user choose item of filter menu. 当用户选择过滤器菜单项时。
    • when user click on remove filter button. 当用户单击“删除过滤器”按钮时。

And when keypress enter on input filter, this make page postback. 当在输入过滤器上按Enter键时,这会使页面回传。

But i want filter fire when keypress enter on input filter. 但是我想当按键在输入过滤器上输入时过滤器触发。

So i used template on columns: 所以我在列上使用了模板:

                { field: "ShortTitle", title: "Title", filterable: { cell: { template: function (input) { input.width("60%"); input.keydown(preventPost); } }} },

And write a function to prevent postback: 并编写一个防止回发的函数:

function preventPost(e) {
        if (e.keyCode === 13) {
            e.preventDefault();             
        }
    }

But i don't know how to fire event filter when user press ENTER. 但是我不知道当用户按下ENTER时如何触发事件过滤器。

i try to call onblur in preventPost function but it not working. 我尝试在preventPost函数中调用onblur,但是它不起作用。

    function preventPost(e) {
        if (e.keyCode === 13) {
            e.preventDefault();
            this.onblur();
        }
    }

Please show me the way to do this.Thank so much. 请告诉我这样做的方法。非常感谢。

you can add a function in your column field 您可以在列字段中添加函数

filterable: {
    cell: {
        operator: "contains",
        template: function (args) {
            args.element.css("width", "90%").addClass("k-textbox").keydown(function (e) {
                setTimeout(function () {
                    $(e.target).trigger("change");
                });
            });
        },
        showOperators: false
    }
}

for more information you can refer this link https://docs.telerik.com/kendo-ui/controls/data-management/grid/how-to/filtering/grid-filter-as-you-type 有关更多信息,您可以参考此链接https://docs.telerik.com/kendo-ui/controls/data-management/grid/how-to/filtering/grid-filter-as-you-type

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM