【问题标题】:Datatables individual column filtering not working数据表单个列过滤不起作用
【发布时间】:2015-02-28 17:00:56
【问题描述】:

感谢 Stryner 提供代码How to disable a search/filter on a specific column on a datatable?

这正是我想要的。

但是,如果底部 TH 单元格确实在需要的地方显示输入,则在模糊/更改/keyup 时,什么都不会发生...

控制台:未定义不是函数 - 对应“oTable.columns().eq(0).each(function(colIdx){”

你能帮我解决这个问题吗?

谢谢你:))

$('#datos tfoot th').not(":eq(0),:eq(3),:eq(5),:eq(6)") //Exclude columns 0, 3, 5 and 6
                     .each( function ()
                      {
                      var title = $('#example thead th').eq( $(this).index() ).text();
                      $(this).html( '<input type="text" placeholder="Rechercher" />' );
                     });
   var oTable = $('#datos').dataTable();

   oTable.columns().eq( 0 ).each( function ( colIdx ) {
    if (colIdx == 0 || colIdx == 3 || colIdx == 5 || colIdx == 6) return; //Do not add event handlers for these columns

    $( 'input', table.column( colIdx ).footer() ).on( 'keyup blur change', function () {  oTable
                                                                                          .column( colIdx )
                                                                                          .search( this.value )
                                                                                          .draw();
                                                                                        });
}); 

我的服务器端脚本与页面底部daniweb.com/web-development/php/threads/467455/convert-datatables-to-server-side-processing的这个相同

谢谢

【问题讨论】:

  • 这似乎工作正常。在这里查看:jsfiddle.net/yn88cv2q。您可能想要检查您的 jQuery 版本或您的 html 表是否设置正确。
  • 它根本不起作用。底部搜索输入显示正确,但是当我输入内容时没有进行过滤。此外,在控制台中我读到 UNDEFINED IS NOT A FUNCTION,我在 jquery 中还不够好,无法自己解决它......我不知道。请帮帮我:))
  • 在数据表 1.10 版本中查看此链接 DataTable (Server side) Custom Column Search
  • Arka:感谢您的链接。我遵循了第一个示例中给出的代码,但我再次陷入困境:使用 $query .= JOIN 或在我的列“邮政编码城市”上。我得到{"draw":1,"recordsTotal":16,"recordsFiltered":0,"data":[]} ...谢谢,我已经使用了一个星期的数据,尝试了很多代码,公式,我变得疯狂/沮丧/生病,无法使其工作

标签: php jquery datatable datatables input-filtering


【解决方案1】:

请在您的 keyup 事件中尝试此方法,如果有效,请告诉我。我很久以前就用过这个,所以不确定它是否适合你,但也许它会有所帮助:

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

【讨论】:

  • 您好,感谢您的帮助 :) 不幸的是它仍然无法正常工作。
猜你喜欢
  • 2016-07-26
  • 1970-01-01
  • 1970-01-01
  • 2018-09-16
  • 1970-01-01
  • 2014-08-09
  • 1970-01-01
  • 1970-01-01
  • 2016-10-23
相关资源
最近更新 更多