我根据两个 tds 在我的桌子上应用过滤器。过滤器正在工作,但如果没有值匹配,我想显示“未找到记录”消息。
这是一个示例演示:
$("#filter").click(function () {
var tdScoring,tdEarning;
var scoring=$("#scoring1").val();
var earning = $("#earning1").val();
table = document.getElementById("mastermindTable");
tr = table.getElementsByTagName("tr");
for (i = 0; i < tr.length; i++) {
tdScoring = tr[i].getElementsByTagName("td")[4];
tdEarning = tr[i].getElementsByTagName("td")[3];
if (tdScoring || tdEarning) {
if (tdScoring.innerHTML.indexOf(scoring) == 0 && tdEarning.innerHTML.indexOf(earning) == 0) {
tr[i].style.display = "";
}
else {
tr[i].style.display = "none";
}
}
}
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="col-sm-6 col-md-3 p0">
<div class="fixed-table-toolbar">
<div class="bars pull-left">
<div id="toolbar">
<select class="form-control input_billing" id="earning1">
<option value="">Earning</option>
<option value="100">100</option> <option value="150">150</option> <option value="250">250</option>
</select>
</div>
</div>
<div class="bars pull-left">
<div id="toolbar">
<select class="form-control input_billing" id="scoring1">
<option value="">Scoring</option>
<option value="70">70</option> <option value="90">90</option>
<option value="100">100</option>
</select>
</div>
</div>
<button id="filter" class="btn btn-success" style="margin-top:8px;" type="button">Filter</button>
</div>
</div>
<table class="table table-condensed" id="mastermindTable">
<thead>
<tr>
<th width="18%" align="left">Name</th>
<th width="26%" align="left">Email </th>
<th width="20%" align="left">Expertise</th>
<th width="16%" align="left">Earning</th>
<th width="16%" align="left">Scoring</th>
<th width="4%" align="left">Status</th>
</tr>
</thead>
<tbody id="mastermindTableBody">
<tr>
<td>Ammar</td>
<td>[email protected] /cdn-cgi/l/email-protection</td>
<td>PHP</td>
<td>100</td>
<td>70</td>
<td>Active</td>
</tr>
<tr>
<td>Arsnel</td>
<td>[email protected] /cdn-cgi/l/email-protection</td>
<td>Larave</td>
<td>150</td>
<td>90</td>
<td>Active</td>
</tr>
<tr>
<td>Abeera</td>
<td>[email protected] /cdn-cgi/l/email-protection</td>
<td>CI</td>
<td>250</td>
<td>110</td>
<td>InActive</td>
</tr>
</tbody>
</table>
您还可以提到另一种简单的方法来过滤表并实现此目的。
我只想用 jQuery 和 JS 来实现这个,不需要插件。
只需添加一个新的 tr,其中包含“未找到记录”消息并显示:无。
jsfiddle 在这里:
demo http://jsfiddle.net/mobensarwar/2ztq7eyx/2/
<tr id="noRecordTR" style="display:none">
<td>No Record Found</td>
</tr>
JavaScript
if(hidden_rows==rows){
for (i = 2; i < tr.length; i++) {
tr[i].style.display = "none";
}
document.getElementById('noRecordTR').style.display = "";
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)