JQUery.DataTables自定义筛选器

JQUery.DataTables自定义筛选器,jquery,asp.net-mvc,datatables,Jquery,Asp.net Mvc,Datatables,在我的ASP.NETMVC应用程序中,我使用jQuery数据表来列出我的客户机。我的jQuery版本是3.3.1。我将此代码用于我的DataTable,它运行良好: 目标是通过另一个搜索输入过滤数据表(应用程序的设计由设计人员实施)。 为了实现这一点,我使用以下代码 <input type="text" onkeyup="filterTable(this);" id="txt-search" maxlength="20" placeholder="Rechercher..." class

在我的ASP.NETMVC应用程序中,我使用jQuery数据表来列出我的客户机。我的jQuery版本是3.3.1。我将此代码用于我的DataTable,它运行良好:

目标是通过另一个搜索输入过滤数据表(应用程序的设计由设计人员实施)。 为了实现这一点,我使用以下代码

 <input type="text" onkeyup="filterTable(this);" id="txt-search" maxlength="20" placeholder="Rechercher..." class="capron-input-text pull-right" />   


//Sets the value of the search input of the datatable and triggers the keyup event. It works fine.
function filterTable(sender) {
    var filterText = $(sender).val();
    var searchInput = $("#tbl-data_filter").find("input");
    $(searchInput).val(filterText);

    $(searchInput).trigger("keyup");
}

 $(document).ready(function() {
  $('#tbl-data').dataTable();

  // These two lines hides related fields. It works.
  $("#tbl-data_filter").hide();
  $("#tbl-data_length").hide();
});
如果我在手动事件中调用这些行,比如任何控件的
click
事件,它会再次工作。我认为
DataTable()
方法是异步的,在它完成我想要隐藏的元素的转换和创建之前,行会执行


有人有什么想法吗?

经过搜索,我找到了以下解决方案:

我在css中添加了这些行

#tbl-data_filter{
   display:none;
}

#tbl-data_length{
  display:none;
}
#tbl-data_filter{
   display:none;
}

#tbl-data_length{
  display:none;
}