【发布时间】:2020-08-31 13:34:53
【问题描述】:
我正在使用Datatables plugin,它会自动允许对所有列进行列过滤。有没有办法让我在我的HTML tables 的第 2 到第 6 列上严格 filtering 我试图遵循这个 jQuery DataTables Filtering for Specific Columns Only 但它对我不起作用。
这是我的工作代码
<script>
$(document).ready(function() {
// Setup - add a text input to each footer cell
$('table thead tr').clone(true).appendTo( 'table thead' );
$('table thead tr:eq(1) th').each( function (i) {
if(i>=1 && i<=6)
var title = $(this).text();
$(this).html( '<input type="text" placeholder="Search '+title+'" />' );
$( 'input', this ).on( 'keyup change', function () {
if ( table.column(i).search() !== this.value ) {
table
.column(i)
.search( this.value )
.draw();
}
} );
} );
var table = $('table').DataTable( {
fixedHeader: true,
columnDefs: [
{ targets: 0, visible: false},
{ targets: '_all', visible: true },
]
} );
} );
</script>
【问题讨论】:
标签: javascript html jquery datatables jquery-plugins