![](/img/trans.png)
[英]bootstrap-table / How to add filter-control in table configuration
[英]How to filter by some column in bootstrap-table?
我有一个表,该表的一列称为“性别”,并且只有两个值:“男性”和“女性”。
我想要的是表格上方的选择,当我选择男性时,只有带有性别列的行等于男性显示。
在bootstrap表中怎么做? 找不到任何类似的例子。
function myFunction() {
var input, filter, table, tr, td, i;
input = document.getElementById("myInput");
filter = input.value.toUpperCase();
table = document.getElementById("myTable");
tr = table.getElementsByTagName("tr");
for (i = 0; i < tr.length; i++) {
td = tr[i].getElementsByTagName("td")[1];
if (td) {
if (td.innerHTML.toUpperCase().indexOf(filter) > -1) {
tr[i].style.display = "";
} else {
tr[i].style.display = "none";
}
}
}
}
在w3schools 这里提供的代码中,您唯一需要做的就是更改td = tr[i].getElementsByTagName("td")[1];
到所需的列号。
您应该使用DataTables,它具有所有功能: https : //datatables.net/examples/styling/bootstrap.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.