dav*_*rad 33
如果您只想在执行搜索时检查值[dataTables 1.10.x ]:
var table = $('#example').DataTable();
$('#example').on('search.dt', function() {
var value = $('.dataTables_filter input').val();
console.log(value); // <-- the value
});
Run Code Online (Sandbox Code Playgroud)
如果要在搜索之前检查值,并且能够取消搜索,则必须取消绑定默认搜索框事件并创建自己的事件,如下所示 - 仅在用户输入的字符数超过3个时才搜索:
$('.dataTables_filter input').unbind().keyup(function() {
var value = $(this).val();
if (value.length>3) {
table.search(value).draw();
}
});
Run Code Online (Sandbox Code Playgroud)
演示 - > http://jsfiddle.net/pb0632c3/
要完全重置搜索/过滤器,例如用户是否已删除搜索词:
if (value.length==0) table.search('').draw();
Run Code Online (Sandbox Code Playgroud)