【发布时间】:2019-11-08 04:43:20
【问题描述】:
我正在使用basic column visibility 和individual column searching (text inputs)。
问题是当用户向表格中添加以前隐藏的列时,该列的文本字段框不会出现。因此,用户无法过滤该列。
有人知道如何为隐藏列启用过滤器吗?理想情况下,这不会导致清除其他过滤器中的文本的副产品(如果用户确实在其他过滤器中输入了文本)。
这是我的过滤代码:
<script type="text/javascript">
$(document).ready(function() {
// Setup - add a text input to each footer cell
$('#tableID tfoot th').each( function () {
var title = $(this).text();
if ((title != '') && !(title.includes("$"))) {
// Then the current column is *not* the Action column.
$(this).html( '<span style="color: #515151; font-size:15px;"><i>Filter</i></span> <br> <input type="text" style="margin-top:10px;" placeholder="'+title+'" /> ' );
}
} );
var table = $('#tableID').DataTable();
// Apply the search
table.columns().every( function () {
var that = this;
$( 'input', this.footer() ).on( 'keyup change', function () {
if ( that.search() !== this.value ) {
that
.search( this.value )
.draw();
}
});
} );
} );
</script>
我正在使用这一行来隐藏我想在默认情况下隐藏的列:
(table.column('.hideCol')).visible(false);
【问题讨论】:
标签: javascript jquery datatables filtering visibility