【发布时间】:2020-10-04 12:38:49
【问题描述】:
单击 Datatables.net 的导出按钮时出现以下错误。
以下是我的代码
$.ajax({
type: "POST",
url: uri,
data: JSON.stringify(args),
contentType: "application/json;charset=utf-8",
success: function (data, status, xhr) {
//alert("The result is : " + data);
if (!data.d) {
$("#gvCurr").DataTable();
}
else {
$("#gvCurr").DataTable({
"aaData": JSON.parse(data.d),
"bDestroy": true,
dom: 'Bfrtip',
deferRender: true,
"bLengthChange": false,
"bPaginate": false,
buttons: [
{
extend: 'excel',
text: '<i class="fas fa-file-excel"></i> Export',
className: "btn btn-primary",
filename: 'DomesticInvoiceReport - ' + moment().format("DD-MMM-YYYY"),
}
],
"columns": [
{ "data": "ProjectNo" },
{ "data": "CountryName" },
{ "data": "StateName" },
{ "data": "SectorName" },
{ "data": "CoOrdName" },
{ "data": "Curr1" },
{ "data": "InvoiceNo_1" },
{ "data": "InvoiceDate_1" },
{ "data": "Month_1" },
{ "data": "Year_1" },
{ "data": "TotalFee_1" },
{ "data": "EscalationAmt_1" },
{ "data": "CurrentOPEAmt_1" },
{ "data": "CGSTPerc" },
{ "data": "SGSTPerc" },
{ "data": "TotalTaxPerc_1" },
{ "data": "TotalTaxAmt_1" },
{ "data": "CurrentInvoiceAmt_1" },
{
mRender: function (data, type, row) {
if (row.IsWithheld_1 == "" || row.IsWithheld_1 == 0)
return 'No';
}
},
{ "data": "WithheldAmt_1" },
{ "data": "BalanceInHandUptoThisInv_1" }
],
"order": [[0, "asc"]]
});
}
$("#entry").hide();
$("#list").show();
},
error: function (xhr) {
alert(xhr.responseText);
}
});
如果你看到 int 代码,如果我注释掉 { "data": "Year_1" } 之后的列,它正在生成 excel 文件,如果我在之后包含列,它会给我显示的错误附上的图片。所以不是代码不正确或者js文件顺序不正确的问题
我已将这些设置包含在 web.config 中
<httpRuntime targetFramework="4.7.2" maxRequestLength="2147483647" requestLengthDiskThreshold="2097152" executionTimeout="240" />
<jsonSerialization maxJsonLength="2147483644" />
它在检索时正确显示记录。在导出时它给出错误。我不确定我在这里缺少什么。
【问题讨论】:
标签: c# jquery datatables-1.10