这是我的代码:
$(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 ); } ); } } );