[英]DataTables - how to filter across multiple columns?
我希望能夠使用DataTables按多個列進行過濾。 現在,我正在使用fnFilter()進行過濾,但是它的column參數似乎只接受一個整數,而不是一個列數組。 這是我到目前為止的內容: https : //jsfiddle.net/dmcgrew/x85o0mgL/2/
在“允許的峰值”列中,我具有設置了yescrest
或nocrest
的data-search
屬性。 我也想使用“ Crest”復選框來進行過濾。
如果單擊“原始”和“波峰”復選框,則應該看到兩個允許波峰的原始項目。
您可以檢出此 DataTables插件,該插件允許多列多標准過濾(包括聯合選擇)。
這是工作的演示 :
$(document).ready(function () { //Source data definition var tableData = [ {item: 'banana', category: 'fruit', color: 'yellow'}, {item: 'pear', category: 'fruit', color: 'green'}, {item: 'cabbage', category: 'vegie', color: 'green'}, {item: 'carrot', category: 'vegie', color: 'red'}, {item: 'apple', category: 'fruit', color: 'red'}, {item: 'kiwi', category: 'fruit', color: 'brown'} ]; //DataTable definition window.dataTable = $('#mytable').DataTable({ sDom: 'tF', data: tableData, columns: [{ data: 'item', title: 'Item' }, { data: 'category', title: 'Category' }, { data: 'color', title: 'Color' }] }); });
<!doctype html> <html> <head> <script src="https://code.jquery.com/jquery-3.3.1.min.js"></script> <script src="https://cdn.datatables.net/1.10.19/js/jquery.dataTables.min.js"></script> <script src="https://cdn.mfilter.tk/js/mfilter.min.js"></script> <link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.10.19/css/jquery.dataTables.min.css"> <link rel="stylesheet" type="text/css" href="https://cdn.mfilter.tk/css/mfilter.min.css"> </head> <body> <table id="mytable"></table> </body> </html>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.