我正在使用 C# 和 JQuery 数据表构建报告仪表板。页面上的其中一个报告包含一个带有下拉列表的更新面板。当用户更改选择时,数据会根据 ddl 选择进行刷新。在每个 block 中还有一个链接,可以调用服务器端将数据导出到 Excel。问题是,在我单击 Excel 导出链接后,下拉列表失去了任何功能,其他 Excel 下载链接也是如此。
这是我的代码:
<div id="dTopProducts" class="dashboardDiv" style="height:400px; width:485px; margin-top: 15px; margin-bottom:15px; margin-right: 15px;" runat="server">
<asp:UpdatePanel ID="upProducts" runat="server">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="ddlProductsSector" EventName="SelectedIndexChanged" />
</Triggers>
<ContentTemplate>
<div style="float: left;">
<h2>Top Products </h2>
</div>
<div style="float: left; ">
<asp:DropDownList
ID="ddlProductsSector"
AutoPostBack="true"
EnableViewState="true"
OnSelectedIndexChanged="ddlProductsSector_SelectedIndexChanged"
runat="server" />
</div>
<asp:UpdateProgress ID="prgProducts" AssociatedUpdatePanelID="upProducts" runat="server">
<ProgressTemplate>
<epriLoader:Loader runat="server" />
</ProgressTemplate>
</asp:UpdateProgress>
<asp:ListView
ID="lvTopProducts"
runat="server">
<ItemTemplate>
<tr style="padding-top: 5px; padding-bottom: 5px;">
<td style="padding-left: 0px;"><%# Eval("productId") %></td>
<td><%# Eval("productDesc") %></td>
<td style="text-align: right;"><%# Eval("quantity") %></td>
</tr>
</ItemTemplate>
<EmptyDataTemplate>
<div style="float: left; padding-top: 25px;">
There are no product records found for the criteria provided
</div>
</EmptyDataTemplate>
<LayoutTemplate>
<table id="tblTopProducts" style="width: 100%">
<thead>
<tr style="padding-bottom: 10px; border: none;">
<th style="text-align: left; border: none; padding-left: 0px;">ID</th>
<th style="text-align: left; border: none; padding-left: 0px;">Name</th>
<th style="text-align: right; border: none;">Quantity</th>
</tr>
</thead>
<tfoot>
<tr>
<td style="border: none;"></td>
<td style="border: none;"></td>
<td style="border: none;"></td>
</tr>
</tfoot>
<tbody runat="server">
<asp:PlaceHolder ID="itemPlaceholder" runat="server" />
</tbody>
</table>
</LayoutTemplate>
</asp:ListView>
</ContentTemplate>
</asp:UpdatePanel>
<%--Link that calls full export from funding page--%>
<a id="aTopProducts" class="invoicesLink" title="Click here to download full report" onserverclick="ExportTopProductsToExcel" runat="server">Download full Report</a>
</div>
这是 jQuery:
function bindTopProductsTable() {
var topProductsTable = $('#tblTopProducts').dataTable(
{
"scrollY": "225px",
"scrollCollapse": true,
"bSort": true,
"order": [[2, "desc"]],
"paging": false,
dom: '<"toolbar">rt<"floatRight"B><"clear">',
buttons: {
buttons: [
{ extend: 'excel', text: 'Export to Excel', exportOption: { page: 'current' }, footer: true, className: 'productsExportButton' }
]
}
});
};
此代码用于处理更新面板:
$(function () {
bindTopProductsTable(); // bind data table on first page load
Sys.WebForms.PageRequestManager.getInstance().add_endRequest(bindTopProductsTable); // bind data table on every UpdatePanel refresh
});
我得到的错误是:
无法获取未定义或空引用的属性“样式”。
这是来自 IE JS 调试器的完整错误:
j.find("thead, tfoot").remove();j.append(h(a.nTHead).clone()).append(h(a.nTFoot).clone());j.find("tfoot th, tfoot td").css("width","");n=qa(a,j.find("thead")[0]);for(m=0;m<i.length;m++)o=c[i[m]],n[m].style.width=null!==o.sWidthOrig&&""!==o.sWidthOrig?x(o.sWidthOrig):"",o.sWidthOrig&&f&&h(n[m]).append(h("<div/>").css({width:o.sWidthOrig,margin:0,padding:0,border:0,height:1}));if(a.aoData.length)for(m=0;m<i.length;m++)t=i[m],o=c[t],h(Gb(a,t)).clone(!1).append(o.sContentPadding).appendTo(r);h("[name]",
毫不奇怪,这在 Chrome 中运行良好,在 IE 中爆炸。
最佳答案
我想通了。原来 Sharepoint 有一个标志来防止有人点击按钮两次。我添加了这段代码:
function setFormSubmitToFalse() {
setTimeout(function () { _spFormOnSubmitCalled = false; }, 3000);
return true;
}
现在一切正常。
关于javascript - jQuery 数据表 ASP.NET 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39774300/