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

问题描述

我正在使用 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 当检测到返回键(keyCode 13)时.

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 when the return key (keyCode 13) is detected.

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

其他

$(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);
    }
   });
} );

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

09-13 15:23