javascript - jQuery 数据表 : Individual column searching on table header

标签 javascript jquery datatable datatables

我已按照 Individual column searching (text inputs) 上的步骤操作和 Individual column searching (select inputs)jQuery DataTable 上使用多个过滤器页脚上有多个过滤器。另一方面,我想将这些过滤器移动到 DataTable 的标题,但无法水平对齐它们,如下图所示。有一些例子,如 Custom filtering - range search ,但它们也没有对齐。是否有可能做到这一点?

$(document).ready(function() {
    // Setup - add a text input to each footer cell
    $('#example tfoot th').each( function () {
        var title = $(this).text();
        $(this).html( '<input type="text" placeholder="Search '+title+'" />' );
    } );

    // DataTable
    var table = $('#example').DataTable();

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

enter image description here

最佳答案

这里是解决方案,请添加必要的数据表配置。

使用 CSS 将列过滤器从页脚移动到表头,即仅使用

<style>
tfoot {
     display: table-header-group;
}
</style>

https://jsfiddle.net/dipakthoke07/ehhfsrfq/2/

希望对你有帮助。

关于javascript - jQuery 数据表 : Individual column searching on table header,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40571553/

相关文章:

vb.net - 使用 .Skip() 和 .Take() 方法对 DataTable 进行 Linq

javascript - 在数据表上填充数据不起作用

c# - 在大容量复制之前将 DBNull 值插入 DataTable 列

javascript - 美国队长与 svg

javascript - 跟踪 Javascript 代码的最佳方式

jquery - 防止 ASP.NET MVC bundle 加载多次

在 View 内渲染时,JQuery 就绪函数不执行

javascript - 如何打开新克隆的 Bootstrap 选择字段?

php - 在 php echo 语句中使用参数调用 javascript 函数

jQuery .css() 在 FF 和 IE 中的行为不同