为什么数据表不刷新?我发送参数并调用get,它将在第一次而不是第二次加载数据,即不是新数据。它确实调用存储过程并获取数据,但数据表从未刷新。为什么?
var url = '@Url.Action("ServicesDetailedReportPartyWise")';
var data = { FromDate: $("#FromDate").val(), ToDate: $("#ToDate").val(), PartyName: $("#PartyName").val() }
$.post(url, data, function (response) {
if (response.ReturnStatusJSON == true) {
$("#tbodytblServicesReport").html("");
var counter = 1;
$.each(response.lstDetailedServicesReturned, function (i, val) {
$("#tbodytblServicesReport").append($('<tr>').append($('<td>').html(i))
.append($('<td>').html((val.EntryDateTime === null || val.EntryDateTime === "") ? "N/A" : formatJSONDate(val.EntryDateTime)))
.append($('<td>').html(val.InvoiceNo))
.append($('<td>').html(val.CustomerName))
.append($('<td>').html(val.VehicleRegNo))
.append($('<td>').html(val.ServiceName))
.append($('<td>').html(val.PartyName))
.append($('<td>').html(val.ServicePrice))
.append($('<td>').html(val.Commission))
)
i++;
$('tfoot td#tdTotal').text(val.TotalCost);
$('tfoot td#tdTotalCommission').text(val.TotalCommission);
$('tfoot td#tdTotalCostMinusTotalCommission').text(val.TotalCostMinusTotalCommission);
$('tfoot td#tdTotalExpenses').text("-"+val.TotalOtherExpenses);
$('tfoot td#tdTotalCostMinusCommissionMinusTotalOtherExpenses').text(val.TotalCostMinusCommissionMinusTotalOtherExpenses);
//
counter = i;
})
if (counter <= 1)
{
$('tfoot td#tdTotal').text("");
$('tfoot td#tdTotalCommission').text("");
$('tfoot td#tdTotalCostMinusTotalCommission').text("");
$('tfoot td#tdTotalExpenses').text("");
$('tfoot td#tdTotalCostMinusCommissionMinusTotalOtherExpenses').text("");
return;
}
$('#tblServicesReport').show();
$('#tblServicesReport').DataTable({
destroy: true,
bPaginate: false,
dom: 'Bfrtip',
buttons: [
'copyHtml5',
'excelHtml5',
'csvHtml5',
{
extend: 'pdfHtml5',
footer: true,
title: 'Services Report (' + $('#FromDate').val() + ' - ' + $('#ToDate').val() + ')',
customize: function (doc) {
doc.styles.title = {
color: 'gray',
fontSize: '15',
alignment: 'center'
}
doc.content[1].table.widths =
Array(doc.content[1].table.body[0].length + 1).join('*').split('');
doc.styles.tableHeader.fontSize = 10;
doc.styles.tableHeader.alignment = 'left';
doc.styles.tableHeader.color = 'white'
}
},
{
extend: 'print',
footer: true
//title: 'Sales Report'
}
]
});
}
}
});
我尝试销毁为true,funDestroy等,但似乎没有任何效果。除了使用数据表之外,我还有其他方法,它似乎每次都会产生问题。有什么解决办法吗?