I am using jQuery DataTables latest version. I want to use individual column filter on every table so am using the column filter plugin but am getting search boxes in foote
Use the sPlaceHolder
option :
sPlaceHolder: "head:before"
example :
dataTable.columnFilter({
sPlaceHolder: "head:before",
aoColumns: [
{ type: "select" },
{ type: "select" },
{ type: "select" },
{ type: "select" },
{ type: "select" }
]
});
see demo -> http://jsfiddle.net/JNxj5/
You can move it to the top of your table by adding the parameter 'sPlaceHolder'
}).columnFilter({
sPlaceHolder: "head:after",
aoColumns: [ ...
Try this
$(document).ready(function() {
$('#mytable thead td').each( function () {
var title = $('#mytable thead th').eq( $(this).index() ).text();
$(this).html( '<input type="text" placeholder="Search '+title+'" />' );
});
$("#mytable thead input").on( 'keyup change', function () {
table
.column( $(this).parent().index()+':visible' )
.search( this.value )
.draw();
});
});
CSS:
tfoot input {
width: 100%;
padding: 3px;
box-sizing: border-box;
}
tfoot {
display: table-header-group;}
Script:
$(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();
}
} );
} );
} );
In CSS you can use
display: table-header-group; //on tfoot
and
display: table-row-group; //on thead
You'll get them positioned like this:
tfoot
thead
tbody
You could change the CSS to
tfoot {
display: table-header-group;
}
Put the filter row stuff into the THEAD as TDs (not THs) and change
$("tfoot input")
to
$("thead input")