2013-04-05 158 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