javascript - 使用单个搜索按钮和清除按钮搜索数据表
问题描述
我正在实现数据表 ajax-grid,我正在使用 bigcommerce API 加载数据。我已经实现了一个按列搜索框。但问题在于它是实时搜索的。我不想要它。我想要做的是在最后一列中需要一个搜索按钮和一个清除按钮。
现在假设我在产品名称的搜索框中输入了一个关键字,并且在 SKU 中也输入了一个关键字。现在,当我按下搜索按钮时,它应该使用这两个关键字进行搜索。我该怎么做?
这是我的代码
HTML
<table id="example" class="display" style="width:100%">
<thead>
<tr>
<th>Image</th>
<th>Product SKU</th>
<th>Product Name</th>
<th>Price</th>
<th>Status</th>
<th>Actions</th>
</tr>
</thead>
<tfoot>
<tr>
<th>Image</th>
<th>Product SKU</th>
<th>Product Name</th>
<th>Price</th>
<th>Status</th>
<th>Actions</th>
</tr>
</tfoot>
</table>
JS
$('#example thead tr').clone(true).appendTo( '#example thead' );
$('#example thead tr:eq(1) th').each( function (i) {
var title = $(this).text();
$(this).html( '<input class="no_sort" type="text" />' );
$( 'input', this ).on( 'keyup change', function () {
if ( table.column(i).search() !== this.value ) {
table
.column(i)
.search( this.value )
.draw();
}
} );
} );
使用 JS,我在表格标题下方添加过滤器
我想要什么:https ://prnt.sc/pnzygy 目前的样子:https ://prnt.sc/pnzz98
解决方案
var table=$('#example').DataTable();
table.column(2).search("sku").draw(); table.column(3).search("产品名称").draw();
推荐阅读
- java - Unable to install Sikuli
- python - How do I find an optimal combination when an exhaustive search would take way too long?
- vb.net - Convert Datatable as Enumerable to List(Of String)
- r - 分配颜色以遵循特定顺序
- json - 使用 PIXI Js 和 parcel bundler 加载纹理图集
- javascript - 下载 doc/docx Javascript
- javascript - 删除表中的记录时出错 - 方法不允许“405(方法不允许)”
- javascript - 无法使用开放图形元标记从我的 React next.js 网站共享 Facebook/Twitter 内容
- python-3.x - 是否可以编写 python3 selenium 脚本来自动禁用 geckodriver 的 CSP?
- consul - Consul 架构:每台机器的代理数量