【发布时间】:2020-06-03 20:49:07
【问题描述】:
我有一个 DataTable,其中每一行都有一个标签。
<table id="mytable" class="table table-striped table-bordered dt-responsive" width="100%">
<thead>
<tr>
<th>Column1</th>
<th>Column2</th>
</tr>
</thead>
<tbody>
<tr mytag = "tag1">
<td>...</td>
<td>...</td>
</tr>
<tr mytag = "tag2">
<td>...</td>
<td>...</td>
</tr>
</tbody>
</table>
有一个包含所有标签的选择框。
<select id="select_tag" class="select2-original">
<option value="tag1">tag1</option>
<option value="tag2">tag2</option>
</select>
And when a tag is selected, I want to filter the table and only display the rows with the tag but what I did is not working.
var mytable= $('#mytable').DataTable();
$('#select_tag').on('change', function () {
var tagvalue = this.value;
mytable
.rows(function (idx, data, node) {
return node.getAttribute("mytag") == tagvalue? true : false;
})
.draw();
})
也尝试过 .hide(),添加 .data()...目前没有任何效果...
【问题讨论】:
标签: javascript html jquery datatables