我正在尝试将json结果发送到jquery数据表。我有结果,但是当我更改下拉值时,数据表不会刷新。我试过
fnClearTable();
clear();
fnDestroy();
但它有效。
数据表
function table(obj) {
if (obj != null && obj.length > 0) {
// var dynamicColumns = [];
var i = 0;
$.each(obj[0], function (key, val) {
var objectt = { sTitle: key };
dynamicColumns[i] = objectt;
i++;
});
var i = 0;
$.each(obj, function (key, val) {
var rowData = [];
var j = 0;
$.each(obj[i], function (key, val) {
rowData[j] = val;
j++;
});
rowDataSet[i] = rowData;
i++;
});
$('#tbDetails').DataTable({
dom: 'Bfrtip',
"bDestroy": true,
"bretrieve": true,
"bScrollCollapse": true,
"bJQueryUI": true,
"bPaginate": false,
"sScrollY": "200px",
"bInfo": true,
"bFilter": true,
"bSort": true,
buttons: [
'copy', 'csv', 'excel', 'pdf', 'print'
],
"aaData": rowDataSet,
"aoColumns": dynamicColumns //These are dynamically created columns present in JSON object.
});
$("#PlotResults").dialog('open');
}
}
请帮帮我 提前致谢
答案 0 :(得分:1)
你可以这样做:
// Dropdown on change event
$('#myDropdown').on('change', function(){
var myTable = $('#myDataTable').DataTable(); // get the table ID
// If you want totally refresh the datatable use this
myTable.ajax.reload();
// If you want to refresh but keep the paging you can you this
myTable.ajax.reload( null, false );
});