gpt4 book ai didi

jquery - jquery数据表下拉过滤器

转载 作者:行者123 更新时间:2023-12-03 21:47:35 25 4
gpt4 key购买 nike

这是我的代码:

$(document).ready(function() {
/* Initialise the DataTable */
var oTable = $('#example').dataTable({
"oLanguage": {
"sSearch": "Search all columns:"
},
"iDisplayLength": 10,
"bJQueryUI": true,
"sPaginationType": "full_numbers",
"bFilter": true,
});

/* Add a select menu for each TH element in the table footer */
$("thead th").each( function ( i ) {
this.innerHTML = fnCreateSelect( oTable.fnGetColumnData(i) );
$('select', this).change( function () {
oTable.fnFilter( $(this).val(), i );
} );
} );
} );

我使用 jquery datatables 插件,它的工作完美,就像这个例子:

http://www.datatables.net/release-datatables/examples/api/multi_filter_select.html

我想要做的是,我不想为每一列都有一个下拉列表,而是只希望在一个特定列上有一个下拉列表。

所以我想我需要改变:

$("thead th").each( function ( i ) {

但我不知道该放什么。任何帮助将不胜感激,提前致谢。

最佳答案

您还可以创建自己的选择列表并将其放置在表格外您喜欢的任何位置。

<select id="mySelect">
<option value="">Select</option>
<option value="1">1</option>
...
</select>

<script>
$('#mySelect').on('change',function(){
var selectedValue = $(this).val();
oTable.fnFilter("^"+selectedValue+"$", 0, true); //Exact value, column, reg
});
</script>

关于jquery - jquery数据表下拉过滤器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9616841/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com