下拉过滤器 jquery 数据表 [英] Dropdown filter jquery datatables

查看:20
本文介绍了下拉过滤器 jquery 数据表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的代码:

$(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 数据表插件,它就像这个例子一样完美地工作:

Im using the jquery datatables plugin, its working perfectly just like this example:

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

我想要做的不是为每一列设置一个下拉列表,而是只在一个特定的列上创建一个下拉列表.

What i would like to do is rather than having a dropdown for each column i would like a dropdown only on one specific column.

所以我想我需要改变:

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

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

But im not sure what to put. Any help would be much appreciated, thanks in advance.

推荐答案

如果你只需要一栏,你可以这样做

If you need only on one column you could do

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 );
      } );
    }
} );   

这篇关于下拉过滤器 jquery 数据表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆