JQUery.DataTables自定义filter

在我的ASP.NET MVC应用程序中,我使用jQuery DataTables来列出我的客户端。 我的jQuery版本是3.3.1。 我将此代码用于我的DataTable,它工作正常:

目标是通过另一个搜索输入过滤数据表(应用程序的设计由设计者强加)。 为此,我使用此代码

 //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(); }); 

当我使用此代码翻译DataTable时,本地化工作正常但搜索输入和行计数下拉保持可见:

  $(document).ready(function () { $('#tbl-data').dataTable({ "language": { "url": "/Resources/Localisation/French.json" } }); // It doesn't work. $("#tbl-data_filter").hide(); $("#tbl-data_length").hide(); }); 

如果我在手动事件中调用这些行,例如任何控件的click事件,它将再次起作用。 我认为DataTable()方法是异步的,在它完成我想要隐藏的元素的转换和创建之前,这些行是执行的。

有没有人有任何想法?

经过一番搜索,我找到了这个解决方案:

我在我的CSS中添加了这些行

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