如何过滤bootstrap-table中的某些列?

时间:2016-03-02 02:37:28

标签: javascript twitter-bootstrap bootstrap-table

我有一个名为性别的列表,只有两个值:男性和女性。

我想要的是桌子上方的选择,当我选择男性时,只有性别列的行等于男性节目。

如何在bootstrap-table中执行此操作?找不到任何类似的例子。

2 个答案:

答案 0 :(得分:0)

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提供的代码here中,您唯一需要的是将td = tr[i].getElementsByTagName("td")[1];中的数字更改为您需要的列数。

答案 1 :(得分:-1)

您应该使用DataTables,它包含所有内容:https://datatables.net/examples/styling/bootstrap.html