jquery数据表中的单个列过滤

时间:2016-02-19 05:38:41

标签: jquery asp.net-mvc

我有以下数据表。我想对每条记录应用单独的列过滤。请告诉我如何在此表中执行此操作

if ($("#example13") !== null) {
    $('#example13').DataTable({
        "stateSave": true,
         "language": {
            "searchPlaceholder": "Search",
            "lengthMenu": "Showing _MENU_ Users",
            "zeroRecords": "Sorry No user(s) found",
            "info": "Showing  _START_ of _END_ of _TOTAL_ Users",
            "infoEmpty": "Sorry No user(s) found ",
            "infoFiltered": "(filtered from _MAX_ TOTAL Users)"
        }
    });
}

1 个答案:

答案 0 :(得分:0)

首先在数据表中每列的顶部或底部放置一个搜索框:

// var table= $('#example13').DataTable({..............
$('#example13 tfoot th').each( function () {
    var title = $(this).text();
    $(this).html( '<input type="text" placeholder="Search '+title+'" />' );
} );

然后在每列上绑定数据表的column().search()函数:

    table.columns().every( function () {     
    var that = this;

    $( 'input', this.footer() ).on( 'keyup change', function () {
        if ( that.search() !== this.value ) {
            that
                .search( this.value )
                .draw();
        }
    } );
} );