0
我正在創建一個DataTables表,其中數據來自AJAX調用,並且加載正常。搜索也很好。當我爲多過濾器選擇添加代碼時,會顯示下拉列表,但它們是空的。我正在爲jQuery和DataTables使用最新的庫。DataTables multi-filter-select not populate dropdown
JS
function overview() {
$.ajax({
url: "/_inc/_ajax/ajax.tables.php",
dataType: 'json',
success: function(results) {
var table = $('#overviewTable').DataTable
({
initComplete: function() {
this.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>')
});
});
}
});
table.clear();
for(var i = 0; i < results["id"].length; i++) {
table.row.add(
[
results["id"][i],
results["title"][i],
results["Tier"][i],
results["region"][i],
results["2016"][i],
results["2017"][i],
results["Letter_Type"][i],
results["Change_Type"][i],
]
).draw();
}
},
error: function (xhr, ajaxOptions, thrownError) {
alert("ERROR: " + xhr.responseText + " - " + thrownError);
}
});
}
HTML
<table id="overviewTable" class="table table-striped table-bordered" cellspacing="0" width="100%">
<thead>';
<tr>
<th>ID</th>
<th>TITLE</th>
<th>TIER</th>
<th>REGION</th>
<th>2016</th>
<th>2017</th>
<th>LETTER TYPE</th>
<th>CHANGE TYPE</th>
</tr>
</thead>
<tfoot>
<tr>
<th>ID</th>
<th>TITLE</th>
<th>TIER</th>
<th>REGION</th>
<th>2016</th>
<th>2017</th>
<th>LETTER TYPE</th>
<th>CHANGE TYPE</th>
</tr>
</tfoot>
</table>';