Datatable dropdown filters are not being displayed
Datatable dropdown filters are not being displayed
michaelchik
Posts: 2Questions: 1Answers: 0
I am trying to display the datatable with dropdown column filters described hear https://datatables.net/examples/api/multi_filter_select.html Although the plugin obviously works since I can see pagination, search field and other common features of DT I still don't see the dropdowns.
$(document).ready(function () {
$('#myselector').DataTable({
initComplete: function () {
this.api().columns().every(function () {
var column = this;
var select = $('<select><option value=""></option></select>')
.appendTo($(column.footer()).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>')
});
});
}
});
});
Edited by Kevin: Syntax highlighting. Details on how to highlight code using markdown can be found in this guide
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
Typically this problem occurs when a footer is not defined. Either add a
tfoot
tag in your html or use jQuery or other Javascript code to create thetfoot
before initializing Datatables. If this doesn't help then we will need to see a test case replicating the issue.https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case
Kevin
thank you Kevin . this has resolved my issue. I attached it to header though but it doesn't matter.