Disabling Search stops individual column searching from working
Disabling Search stops individual column searching from working
jongee
Posts: 2Questions: 1Answers: 0
Hi
I am new to Datatables so still learning the basics. I have set up a table and all works fine until I disable the 'Search' feature. The reason I am disabling it is that I want to use individual column searching using a select field.
My code is below.
$(document).ready(function() {
$('#mainTable').DataTable( {
initComplete: function () {
this.api().columns([2]).every( function () {
var column = this;
var select = $('<select><option value="">User Name</option></select>')
.appendTo( $(column.header()).empty() )
.on( 'change', function () {
var val = $.fn.dataTable.util.escapeRegex(
$(this).val()
);
column
.search( val ? '^'+val+'$' : '', true, false )
.draw();
} );
column.data().unique().sort().each( function ( d, j ) {
select.append( '<option value="'+d+'">'+d+'</option>' )
} );
} );
}, "paging": false,
"ordering": false,
"info": false,
"searching": false
} );
} );
Any help would be great.
This discussion has been closed.
Answers
OK, I have done this using the following...
Not sure if this is right/best method, but it works.