首页 > 解决方案 > 具有固定列的数据表选择过滤器

问题描述

所以,我有一个左侧固定列的 DataTable,但想添加一个 Select like 过滤器,数据表不支持该过滤器。

我创建了选择过滤器,它在没有固定列的情况下工作得很好,因为它从原始表中过滤。问题是当我修复左列时,它不会将过滤器应用于克隆表

我尝试在克隆表中添加和“id”,然后也将过滤器应用到其中,但它不起作用

如图所示,它应用的过滤器“Externas”应该只显示橙色行,但固定列显示每一行

固定列不过滤

这是我的选择

<select id="filtrarTipo" onclick="filtradoTipo(); filtradoTipoC();">
 <option value="" selected disabled>Seleccione</option>
 <option value="">Todas</option>
 <option value="Interna">Interna</option>
 <option value="Externa">Externa</option>
</select>

还有我的jQuery

function filtradoTipo() {
    // Declare variables
    var input, filter, table, tr, td, i, txtValue;
    input = document.getElementById("filtrarTipo");
    filter = input.value.toUpperCase();
    table = document.getElementById("dtBecas");
    tr = table.getElementsByTagName("tr");


    // Loop through all table rows, and hide those who don't match the search query
    for (i = 0; i < tr.length; i++) {
      td = tr[i].getElementsByTagName("td")[4];
      if (td) {
        txtValue = td.textContent || td.innerText;
        if (txtValue.toUpperCase().indexOf(filter) > -1) {
          tr[i].style.display = "";
        } else {
          tr[i].style.display = "none";
        }
      }
    }
  }

标签: datatablesfixed

解决方案


推荐阅读