Can i use header column search datatables laravel instead of footer column search

时间:2017-08-05 11:26:51

标签: laravel datatables

The following script shows the search boxes on table footer section

initComplete: function () {
    this.api().columns().every(function () {
        var column = this;
        var input = document.createElement("input");
        $(input).appendTo($(column.footer()).empty())
            .on('change', function () {
                column.search($(this).val(), false, false, true).draw();
            });
    });
}

Can I display the search box in top of table after the columns names:

I tried to change the function column.footer to column.header ... it not works.

I am using laravel datatables

Thank you

1 个答案:

答案 0 :(得分:2)

使用以下内容,而不是“#users”使用您的表格ID。

"initComplete": function () {
    var r = $('#users tfoot tr');

    $('#users thead').append(r);

    this.api().columns().every(function () {
        var column = this;
        var input = document.createElement("input");
        $(input).appendTo($(column.footer()).empty())
                .on('change', function () {

       column.search($(this).val(), false, false,true).draw();
                });
    });

}