I have added a searchbox to the header of my table generated by the Datatables plugin. It places a searchbox above every column in the header. I need the search filter to be applied to only a few columns. Lets say column 0 and 6 need a search filter the others not. Is there a way to do this? I cant find a answer anywhere on how to make this happen and I am new to coding so I have not yet found a way to make this happen. Below code I use to create the search header.
$('#OBTable thead tr')
.clone(true)
.addClass('filters')
.appendTo('#OBTable thead');
var table = $('#OBTable').dataTable({
"ajax": {
"url": "SelectData.php",
"dataSrc": "data",
},
orderCellsTop: true,
select: true,
initComplete: function () {
var api = this.api();
// For each column
api
.columns()
.eq(0)
.each(function (colIdx) {
// Set the header cell to contain the input element
var cell = $('.filters th').eq(
$(api.column(colIdx).header()).index()
);
var title = $(cell).text();
$(cell).html('<input type="text" placeholder="' + title + '" />');
// On every keypress in this input
$(
'input',
$('.filters th').eq($(api.column(colIdx).header()).index())
)
.off('keyup change')
.on('keyup change', function (e) {
e.stopPropagation();
// Get the search value
$(this).attr('title', $(this).val());
var regexr = '({search})'; //$(this).parents('th').find('select').val();
var cursorPosition = this.selectionStart;
// Search the column for that value
api
.column(colIdx)
.search(
this.value != ''
? regexr.replace('{search}', '(((' + this.value + ')))')
: '',
this.value != '',
this.value == ''
)
.draw();
$(this)
.focus()[0]
.setSelectionRange(cursorPosition, cursorPosition);
});
});
},