dropdowns ONLY for some columns
dropdowns ONLY for some columns
muscaiu
Posts: 6Questions: 4Answers: 0
Using this code, and all examples i've seen, i can add dropdowns to ALL columns like in the picture:
https://drive.google.com/file/d/0B4nUvzf87W8KVzRVY0daZXhmcjg/view
var table = $('#myTable').DataTable({
dom: 'lfBrtip',
initComplete: function () {
this.api().columns().every( function () {
var column = this;
var select = $('<select><option value=""></option></select>')
.appendTo( $(column.header()))
.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>' )
} );
} );
.......
}
How can i add dropdowns ONLY for column 2 and 3 for example?
Thank you.
This discussion has been closed.
Answers
You can apply the dropdown filters to particular columns pretty easily:
...className: "whatever_class_name_you_want"...
to your column definitions.this.api().columns().every( function () {
tothis.api().columns('.whatever_class_name_you_want').every( function () {