我有一個空tbody的HTML表格,它填充jQuery的功能選擇一些過濾器(通常選擇選項)填充。如果表格元素超出限制,DataTable用於分頁。使用jQuery動態更新DataTable內容
當過濾器第一次應用時,它工作正常。但是,當表內容由jquery更新時,DataTable似乎沒有用新數據更新它。
HTML看起來像:
<table class="table table-striped table-hover outline" id="result" >
<thead>
<tr>
<th>Name</th>
<th>ID</th>
<th>Age</th>
<th>Department</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
而jQuery函數:
$(document).ready(function(){
function filterData(list) {
/*filter and send updated list*/
return list;
}
/* some other code */
data = filterData(rawData); //Function will filter the data
var html = ''; //html part to be appended in the results table
data.forEach(function(d) {
html += '<tr>'; //create a table row
for (var key in d)
html += '<td>'+ d[key] +'</td>'; //put all elements in the columns
html += '</tr>';
});
$("#result tbody").html(html); //display the result in table body
$('#result').DataTable({
scrollY:"300px",
lengthMenu: [10,15,20]
});
});
任何可能的方式來更新新內容的DataTable?提前致謝!
您使用的是數據表Api嗎? –
http://stackoverflow.com/questions/27778389/how-to-manually-update-datatables-table-with-new-json-data可能的重複。 – TechnoCrat