要实现Ajax datatables的多列搜索,你可以按照以下步骤进行:
Name
Position
Office
Age
Start date
Salary
Tiger Nixon
System Architect
Edinburgh
61
2011/04/25
$320,800
...
$(document).ready(function() {
var table = $('#myTable').DataTable();
// 添加多列搜索功能
$('#myTable thead tr').clone(true).appendTo('#myTable thead');
$('#myTable thead tr:eq(1) th').each(function(i) {
var title = $(this).text();
$(this).html('');
$('input', this).on('keyup change', function() {
if (table.column(i).search() !== this.value) {
table
.column(i)
.search(this.value)
.draw();
}
});
});
});
这样,你就可以通过在每个表头单元格中输入搜索关键字来实现多列搜索功能了。
上一篇:Ajax DataTable排序
下一篇:AJAX DELETE的问题