这是我的代码:
$(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 ) {
但我不确定要放什么。任何帮助将不胜感激,在此先感谢。
最佳答案
如果只需要一栏,就可以
var indexOfMyCol = 2;//you want it on the third column
$("thead th").each( function ( i ) {
if(i === indexOfMyCol){
this.innerHTML = fnCreateSelect( oTable.fnGetColumnData(i) );
$('select', this).change( function () {
oTable.fnFilter( $(this).val(), i );
} );
}
} );