datatables全局搜索按键输入键而不是任何按键 [英] datatables global search on keypress of enter key instead of any key keypress

查看:321
本文介绍了datatables全局搜索按键输入键而不是任何按键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用jQuery的 Datatables 插件。
我正在为我的ASP.Net项目使用服务器端处理功能。

I am using Datatables plugin of jQuery. I am using server side processing functionality for my ASP.Net project.

当我每次尝试在全局搜索中输入内容时,它会令人沮丧,每个字母我键入它调用服务器端方法并为我带来结果。

Its get frustrating when each time I try to type something in global search, with each letter I type it calls the server side method and brings result for me.

当要过滤的数据很大时,它变得更加沮丧。

It gets more frustrating when the data to be filter is large.

是否有任何选项或方式在按键的按键上调用搜索方法,而不是按任何键?

Is there any option or way to call search method on keypress of enter key and not on any key press?

推荐答案

如何解除DataTables放置在输入框上的按键事件处理程序,然后添加自己的调用fnFilter( http://datatables.net/api#fnFilter )。

What to do is to just unbind the keypress event handler that DataTables puts on the input box, and then add your own which will call fnFilter ( http://datatables.net/api#fnFilter ) when the return key (keyCode 13) is detected.

$("div.dataTables_filter input").keyup( function (e) {
    if (e.keyCode == 13) {
        oTable.fnFilter( this.value );
    }
} );



其他



Else

$(document).ready(function() {
   var oTable = $('#test').dataTable( {
                    "bPaginate": true,
                "bLengthChange": true,
                "bFilter": true,
                "bSort": true,
                "bInfo": true,
                    "bAutoWidth": true } );
   $('#test_filter input').unbind();
   $('#test_filter input').bind('keyup', function(e) {
       if(e.keyCode == 13) {
        oTable.fnFilter(this.value);   
    }
   });     
} );

这篇关于datatables全局搜索按键输入键而不是任何按键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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