[英]How to filter by some column in bootstrap-table?
I have a table with one column called gender, and only have two values: male and female. 我有一个表,该表的一列称为“性别”,并且只有两个值:“男性”和“女性”。
What I want is a select above the table, when I select male, only rows with gender column equals to male shows. 我想要的是表格上方的选择,当我选择男性时,只有带有性别列的行等于男性显示。
How to do it in bootstrap-table? 在bootstrap表中怎么做? cannot find any similiar examples.
找不到任何类似的例子。
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";
}
}
}
}
In the code that w3schools provided here the only thing that you need is to change the number in the td = tr[i].getElementsByTagName("td")[1];
在w3schools 这里提供的代码中,您唯一需要做的就是更改
td = tr[i].getElementsByTagName("td")[1];
to the number of the column that you need. 到所需的列号。
您应该使用DataTables,它具有所有功能: https : //datatables.net/examples/styling/bootstrap.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.