im trying to exclude some columns from having a drop down filter added to them. Ive used IndexOf to try and complete this, however instead of excluded columns 5 and 7, it excludes all columns from 5 so my table for example exlcludes 5,6,7,8 it should only exclude 5 and 7.
here is the code, does anyone know whats wrong?
Thanks
$(document).ready(function() {
$('#cve_list').DataTable( {
"pageLength": 18,
"order": [[ 3, "desc" ]],
responsive: false,
"dom": "<'row'<'col-md-6'l><'col-md-6'Bf>>" +
"<'row'<'col-sm-12'tr>>" +
"<'row'<'col-sm-5'i><'col-sm-7'p>>",
buttons: [
'copyHtml5',
'excelHtml5',
],
columnDefs: [
{
targets: 6,
type: 'html'
},
{
targets: 7,
type: 'html'
}
],
initComplete: function () {
var excluded_columns = [5,7];
this.api().columns().every( function () {
var column = this;
alert(column.index())
if(excluded_columns.indexOf(column.index()) == -1) {
alert('adding column ' + column.index())
var select = $('<br /><select class="dt-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 ) {
if(column.index() == 6){ d = $(d).text(); }
if(column.index() == 7){ d = $(d).text(); }
select.append( '<option value="'+d+'">'+d+'</option>' )
});
});
},
});
});