Sribin Sribin - 1 month ago 6
Javascript Question

How to insert columnfilter in bootstrap datatable

I have bound my html table with datatable and the functionalities such as searching, paging and sorting are working fine. But when I tried to implement the column filter using

$('#table1').DataTable().columnFilter();`


it doesn't work. It shows an error saying


columnFilter is not a function.

Answer

I have done it in a different way.

$('#demo-dt-basic thead tr th').each(function (i) {        
        var title = "Search "+$(this).text();

        $("<input class='form-control input-sm' type='text' placeholder='" + title + "'/>").appendTo($(this));
        table.columns().eq(0).each(function (colIdx) {
            $('input', table.column(colIdx).header()).on('keyup change', function () {
                table
                    .column(colIdx)
                    .search(this.value)
                    .draw();
            });
        });

} );