从 select 过滤不起作用

Filtering not working from select

我创建了一个带有固定 headers 和排序的数据表的应用程序,该应用程序工作正常,但问题是我有一个名称通过 drop-down 过滤,但它不起作用当我 select 一个特定的名字。

我的代码如下。

谁能告诉我一些解决方案:

Working Demo

$(document).ready(function () {
    myTable = $('#myTable').dataTable({
        "bInfo": false,
        "bLengthChange": false,
        "bPaginate": false,
        "scrollY": "300px",
        "scrollX": "100%",
        "scrollCollapse": true,
    });

    new $.fn.dataTable.FixedColumns(myTable, {
        leftColumns: 1,
        rightColumns: 1
    });

    $("#name").on('change', function () {
        filterNames();
    });

    function filterNames() {
        var name = $('#name option:selected').attr('value');
        myTable.fnFilter(name, 14, false, false, false, false);
    }
});

您在 fnFilter 中输入了错误的索引。找到下面的工作代码,

JSFiddle

问题出在 on 事件上,您应该将选择器提供给 on 函数

否则使用

委托:它只是附加事件运行时。有关详细信息,请参阅 http://api.jquery.com/delegate/

需要使用 $(this) 来获取事件处理程序中的选定值。