新需求,在table的各列上方加搜索条件,原来的做法是要传搜索内容给后台,后台返回数据并显示,但是后端最近忙,没时间,就自己研究datatable插件,看看能不能不用ajax,直接用插件本身的可行性
var table = $('.datatable').DataTable({
"bPaginate": false,
"bInfo":false,
"ordering": false,
deferRender: true,
searching :true,//显示搜素输入框功能,css隐藏样式,绑定到table.header()上
});
table.columns().every( function () {
//table.search(true).draw();
var that = this;
$( 'input',this.header() ).on( 'keyup change', function () {
if ( that.search() !== this.value ) {
that
.search( this.value )
.draw();
}
} );
} );
这里用到了一个之前没用过的属性,
this.footer() table 中 tfoot标签内容
this.header() table 中 thead标签内容