2013-04-05 115 views
3

我有一个DataTables表,它通过AJAX源获取数据。我已经准备好了桌子,甚至是搜索作品。jQuery DataTables:每列过滤器

现在我有一个要求为每列实现搜索字段。似乎有一个DataTables插件列过滤,我试图使用。

这是我的HTML:

<!DOCTYPE HTML> 
<html> 
<head> 
    <title>testpage</title> 
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script> 
    <script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.10.0/jquery-ui.min.js"></script> 
    <script type="text/javascript" src="http://www.company.com/content/dam/workflows/js/jquery.dataTables.min.js"></script> 
    <script type="text/javascript" src="http://jquery-datatables-column-filter.googlecode.com/svn/trunk/media/js/jquery.dataTables.columnFilter.js"></script> 
    <script type="text/javascript"> 
    $(document).ready(function() { 
     $("#overview").dataTable({ 
      aoColumnDefs:[{ 
       aTargets: [0] 
      }], 
      bAutoWidth: false, 
      bLengthChange: false, 
      iDisplayLength: 10, 
      sAjaxSource: "http://server/api.jsp?someparameters" 
     }).columnFilter(); 
    }) 
    </script> 
</head> 

<body> 

<table id="overview"> 
<tr> 
    <thead> 
     <th>#</th> 
     <th>Betrieb</th> 
     <th>Status</th> 
     <th>Anlagenummer</th> 
     <th>Bezeichnung</th> 
    </thead> 
</tr> 
</table> 

</body> 
</html> 

正如你所看到的,我刚刚附加columnFilter()方法。它甚至没有在控制台中抛出错误,但是表格看起来和以前一样(没有额外的输入框来搜索列)。

我做错了什么?是否有可能源于Ajax的源头?

+0

哪里是''标签? – asprin 2013-04-05 12:35:19

+0

哦,我的...不能相信我没有看到,非常感谢! – Ahatius 2013-04-09 07:29:29

回答

2

我想你需要在你的html表中定义一个页脚部分。看看this example

表应该看起来像

<table> 
    <thead> 
     <tr>...</tr> 
    </thead> 
    <tfoot> 
     <tr>...</tr> 
    </tfoot> 
</table> 
+0

感谢哥们,那正是导致问题的原因! – Ahatius 2013-04-09 07:29:49

+0

我无法与DataTables 1.10.2一起工作。它是否适用于1.10。+?插件的演示站点仅在2011-2012之前使用Datatables 1.8和1.9。我有一个不好的感觉它不是最新的:( – 2014-12-18 09:10:16