简体   繁体   English

如何使数据表示例“多过滤器”适应多表支持

[英]How to adapt datatables example “multi-filter” for multi-table support

After successfully implementing datatables multi-filter to my system for one table, I'd like to implement it for all of my tables, which are organized by several tabs, like shown here . 在为一个表成功地将datatables多重过滤器实现到我的系统之后,我想为我的所有表实现它,这些表由几个选项卡组织,如此处所示

To reach that, I think I have to set three individual variables: 为此,我认为我必须设置三个单独的变量:

var oTable0 = $('#tabs-0 table.display').dataTable({
var oTable1 = $('#tabs-1 table.display').dataTable({
var oTable2 = $('#tabs-2 table.display').dataTable({

For filtering, I should need something like: 为了进行过滤,我应该需要以下内容:

$("tfoot input").keyup( function () {
/* Filter on the column (the index) of this element */
  oTable0.fnFilter( this.value, $("tfoot input").index(this) );
  oTable1.fnFilter( this.value, $("tfoot input").index(this) );
  oTable2.fnFilter( this.value, $("tfoot input").index(this) );
});

For the table footers I also have to individualize the rows. 对于表脚,我还必须个性化行。 Here an example for the first table: 这是第一个表的示例:

<th>
  <input type="text" name="search_tabs0_rfid" value="Search column" class="search_init0" />
</th>
<th>
  <input type="text" name="search_tabs0_art" value="Search column" class="search_init0" />
</th>
...

For adapting the user friendlyness part I thought of: 为了适应用户友好性部分,我想到了:

$("tfoot input").each( function (i) {
    asInitVals0[i] = this.value;
    asInitVals1[i] = this.value;
    asInitVals2[i] = this.value;
});

$("tfoot input").focus( function () {
    if ( this.className == "search_init0" ){ this.className = ""; this.value = "";}
    if ( this.className == "search_init1" ){ this.className = ""; this.value = "";}
    if ( this.className == "search_init2" ){ this.className = ""; this.value = "";}
});

$("tfoot input").blur( function (i) {
    if ( this.value == "" ){ this.className = "search_init0"; this.value = asInitVals0[$("tfoot input").index(this)];}
    if ( this.value == "" ){ this.className = "search_init1"; this.value = asInitVals1[$("tfoot input").index(this)];}
    if ( this.value == "" ){ this.className = "search_init2"; this.value = asInitVals2[$("tfoot input").index(this)];}
});

Now, the first Tab (#tabs-0) is working fine, but the rest is not. 现在,第一个Tab(#tabs-0)可以正常工作,而其余的则不能。

Maybe the part 也许是一部分

$("tfoot input")

Is a problem because this occurs in every one of the three individual tables. 是一个问题,因为这在三个单独的表的每个表中都发生。

So, how can I get these column searches bound to their specified table? 那么,如何使这些列搜索绑定到其指定的表? Which part did I miss? 我错过了哪一部分?

Cheers, thowi 干杯,thowi

Whenever you want to isolate instances start from an ancestor element that isolates only the instance elements needed which I think could be tfoot in your case. 每当您要隔离实例时,就从祖先元素开始,该祖先元素仅隔离所需的实例元素,我认为在您的情况下可能会很tfoot

$("tfoot input").blur( function (i) {
    /* traverse up the document tree to ancestor needed*/
    var $parent=$(this).closest('tfoot');
    /* index only the inputs in current parent tfoot*/
    var index=$parent.find('input').index(this);
    /* more code*/
});

If you needed to interact with the dataTables API...can look up to the table itself and do something like: 如果您需要与dataTables API进行交互...可以查询表本身并执行以下操作:

$parent.closest('table').datatables_API_method()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM