gpt4 book ai didi

javascript - jQuery 数据表 : hide search bar

转载 作者:行者123 更新时间:2023-12-03 22:54:07 25 4
gpt4 key购买 nike

我似乎无法隐藏 DataTables 默认搜索栏。到目前为止,我已经尝试过 this 的解决方案线程,但设置 bFilter:false 会完全禁用过滤,因此页脚中的搜索框不再起作用。

我已经发布了jsfiddle

我的 HTML:

<thead>
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.10.19/css/jquery.dataTables.css">
<script type="text/javascript" charset="utf8" src="https://cdn.datatables.net/1.10.19/js/jquery.dataTables.js"></script>
</thead>
<tbody>
<table id="mytable">
<thead>
<tr>
<th>name</th>
<th>type</th>
<th>color</th>
</tr>
</thead>
<tfoot>
<tr>
<th></th>
<th></th>
<th></th>
</tr>
</tfoot>
<tbody>
<tr>
<td>apple</td>
<td>fruit</td>
<td>red</td>
</tr>
<tr>
<td>banana</td>
<td>fruit</td>
<td>yellow</td>
</tr>
<tr>
<td>carrot</td>
<td>vegie</td>
<td>red</td>
</tr>
<tr>
<td>potato</td>
<td>vegie</td>
<td>brown</td>
</tr>
</tbody>
</table>
</tbody>

和 jQuery 代码:

$(document).ready(function(){
let table = $('#mytable').DataTable();
$('#mytable tfoot th').each( function (i) {
let title = $('#mytable thead th').eq( $(this).index() ).text();
$(this).html( '<input type="text" placeholder="Search '+title+'" data-index="'+i+'" />' );
} );
$( table.table().container() ).on( 'keyup', 'tfoot input', function () {
table
.column( $(this).data('index') )
.search( this.value )
.draw();
} );
});

非常感谢任何帮助。

最佳答案

您需要相应地调整DataTable的sDom属性:let table = $('#mytable').DataTable({sDom: 'lrtip'});这应该隐藏搜索框而不禁用过滤功能。另外,您可能想查看official reference关于该主题的文档。

关于javascript - jQuery 数据表 : hide search bar,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53885245/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com