Is there please an option to start the search only after 3 characters have been typed in?

I have written a PHP-script for colleagues displaying 20,000 entries and they complain, that when typing a word, the first few letters cause everything to freeze.

另一种 Select 是通过单击按钮而不是通过键入字符来启动搜索.

Below is my current code:

$("#my_table").dataTable( {
        "bJQueryUI": true,
        "sPaginationType": "full_numbers",
        "bAutoWidth": false,
        "aoColumns": [
                /* qdatetime */   { "bSearchable": false },
                /* id */          null,
                /* name */        null,
                /* category */    null,
                /* appsversion */ null,
                /* osversion */   null,
                /* details */     { "bVisible": false },
                /* devinfo */     { "bVisible": false, "bSortable": false }
        ],
        "oLanguage": {
                "sProcessing":   "Wait please...",
                "sZeroRecords":  "No ids found.",
                "sInfo":         "Ids from _START_ to _END_ of _TOTAL_ total",
                "sInfoEmpty":    "Ids from 0 to 0 of 0 total",
                "sInfoFiltered": "(filtered from _MAX_ total)",
                "sInfoPostFix":  "",
                "sSearch":       "Search:",
                "sUrl":          "",
                "oPaginate": {
                        "sFirst":    "<<",
                        "sLast":     ">>",
                        "sNext":     ">",
                        "sPrevious": "<"
                },
                "sLengthMenu": 'Display <select>' +
                        '<option value="10">10</option>' +
                        '<option value="20">20</option>' +
                        '<option value="50">50</option>' +
                        '<option value="100">100</option>' +
                        '<option value="-1">all</option>' +
                        '</select> ids'
        }
} );

推荐答案

Solution for version 1.10 -

After looking here for a complete answer and not finding one, I've written this (utilizing code from the documentation, and a few answers here).

以下代码用于延迟搜索,直到至少输入3个字符:

// Call datatables, and return the API to the variable for use in our code
// Binds datatables to all elements with a class of datatable
var dtable = $(".datatable").dataTable().api();

// Grab the datatables input box and alter how it is bound to events
$(".dataTables_filter input")
    .unbind() // Unbind previous default bindings
    .bind("input", function(e) { // Bind our desired behavior
        // If the length is 3 or more characters, or the user pressed ENTER, search
        if(this.value.length >= 3 || e.keyCode == 13) {
            // Call the API search function
            dtable.search(this.value).draw();
        }
        // Ensure we clear the search if they backspace far enough
        if(this.value == "") {
            dtable.search("").draw();
        }
        return;
    });

Jquery相关问答推荐

点击和touch 事件之间的jQuery冲突解决方法

是否可以从不可见的 DataTables 列访问数据?

使用 JQuery 在 span 标签中用逗号分隔页面上的文本

为什么我不能在 window.onload 事件的处理程序中将 $ jQuery 对象作为参数传递?

未捕获的类型错误:无法读取未定义的属性toLowerCase

为什么对同一个 ASP.NET MVC 操作的多个同时 AJAX 调用会导致浏览器阻塞?

显示的 jQuery 日期 Select 器年份

使用 jQuery 将行添加到表的 tbody

实用的 javascript 面向对象设计模式示例

jQuery - 使用发布数据重定向

为什么找不到我的 json 文件?

jQuery:获取父母,父母ID?

DataTables:无法读取未定义的属性长度

带有 jquery 的 jsonp

使用 AJAX 加载 Bootstrap 弹出内容.这可能吗?

jquery 检测某些类的 div 已添加到 DOM

如何使用 jQuery 删除 cookie?

如何使用 jQuery 检测 IE 8?

你如何记录jQuery中一个元素触发的所有事件?

如何使用 JQuery 删除onclick?