列筛选器不能与行分组一起工作

Column filter is not working with row grouping

本文关键字:一起 工作 筛选 不能      更新时间:2023-09-26

当我集成jQuery数据表列过滤器和行分组时,jQuery数据表列过滤器不工作

我尝试了演示,但似乎在演示列过滤器也不工作。

<

解决方案/strong>

插件行分组和列过滤不再被开发,我不建议使用它们。使用datattables选项和API方法执行行分组和单列搜索,如行分组示例和单列搜索示例所示。

// Setup - add a text input to each footer cell
$('#example tfoot th').each( function () {
    var title = $('#example thead th').eq( $(this).index() ).text();
    $(this).html( '<input type="text" placeholder="Search '+title+'" />' );
} );
// DataTable
var table = $('#example').DataTable({
    "order": [[2, 'asc']],
    "drawCallback": function (settings){
        var api = this.api();
        // Zero-based index of the column for row grouping
        var col_name = 2;
        // If ordered by column containing names
        if (api.order()[0][0] === col_name) {
            var rows = api.rows({ page: 'current' }).nodes();
            var group_last = null;
            api.column(col_name, { page: 'current' }).data().each(function (name, index){
                var group = name;
                if (group_last !== group) {
                    $(rows).eq(index).before(
                        '<tr class="group"><td colspan="6">' + group + '</td></tr>'
                    );
                    group_last = group;
                }
            });
        }
    }
});
// Apply the 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();
        }
    } );
} );