jQuery DataTables 插件——添加自定义选项选择过滤器
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2879540/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
jQuery DataTables plugin -- adding a custom option select filter
提问by Jeffrey
Anyone know how to add a custom option select filter to a jQuery DataTable?
任何人都知道如何向 jQuery DataTable 添加自定义选项选择过滤器?
Basically, like this example pagebut instead of having min/max text fields... change them to select options.
基本上,就像这个示例页面一样,但不是有最小/最大文本字段......将它们更改为选择选项。
回答by Jeffrey
Easier than I thought it would be:
比我想象的要容易:
Javascript
Javascript
$(document).ready(function() {
/* Initialise datatables */
var oTable = $('#example').dataTable();
/* Add event listener to the dropdown input */
$('select#engines').change( function() { oTable.fnFilter( $(this).val() ); } );
} );
HTML
HTML
<select id="engines">
<option value="">- Select -</option>
<option value="1.8">1.8</option>
<option value="1.9">1.9</option>
</select>
回答by MetalKid
You need to build a regular expression that will do it. Making a minimum or maximium is fairly easy. Trying to do both at the same time gets tricky. Here is one that will return all numbers 13+:
您需要构建一个可以做到这一点的正则表达式。制作最小值或最大值相当容易。试图同时做这两件事会变得棘手。这是一个将返回所有 13+ 数字的方法:
oTable.fnFilter("([1-9][3-9]|[2-9][0-9]|[0-9]{3,})", 1, true);
This says: 13-99 (excluding 20, 21, 22, 31, 32, etc) 20-99 100+
这表示:13-99(不包括 20、21、22、31、32 等)20-99 100+