2016-10-26 26 views
1

我正在使用DataTables jQuery插件,但我遇到了問題 獲取全局輸入搜索框將是一個選擇框。如何使用外部選擇框過濾數據表?

隨着sDOM選項lrtip,過濾輸入不顯示,但是是 它可能顯示選擇框和獲取數據表基於選擇框的變化過濾?

JS:

$(document).ready(function() { 
    var table = $('#table_page').DataTable({ 
     paging: true, 
     ordering: false,   
     info:  true, 
     searching: true, 
     sDom: "lrtip" // default is lfrtip, where the f is the filter 
    }); 
}); 

HTML:

<table id="table_page" class="display cell-border" width="100%"> 
    <thead> 
     <tr> 
      <th>Column 1</th> 
      <th>Column 2</th> 
     </tr> 
    </thead> 
</table> 
+0

你見過[單獨列搜索(選擇輸入)示例](https://datatables.net/examples/api/multi_filter_select.html)? –

+0

是的,但我希望全局搜索不是單個列搜索。 – LeMoussel

+0

看起來像你的答案在這裏: http://stackoverflow.com/questions/12199759/datatables-custom-filtering –

回答

6

您可以使用search() API方法進行全局搜索程序和dom選項可以禁用內置的搜索控制。

例如:

var table = $('#example').DataTable({ 
    dom: 'lrtip' 
}); 

$('#table-filter').on('change', function(){ 
    table.search(this.value).draw(); 
}); 

this example參見代碼和示範。如果您想替換默認搜索框,請參見this example

+0

好的,但是你認爲是否有可能在與「顯示條目」相同的行中有選擇框(如帶有sDom'lfrtip'選項的輸入搜索框) – LeMoussel

+0

@ Gyrocode.com哇! 更新您的答案,讓我接受它。感謝您的幫助,歡呼。 – LeMoussel

+0

@LeMoussel,更新了答案。另外在最後一個例子中有一個錯誤被糾正,請參閱https://jsfiddle.net/zmoos6tu/3 –

相關問題