【问题标题】:jQuery Datatables ASP.NET issuejQuery 数据表 ASP.NET 问题
【发布时间】:2016-09-29 15:23:58
【问题描述】:

我正在使用 C# 和 JQuery 数据表构建报告仪表板。该页面上的一份报告包含一个带有下拉列表的更新面板。当用户更改选择时,数据会根据 ddl 选择刷新。在每个块内还有一个链接,可以进行服务器端调用以将数据导出到 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&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</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 中崩溃了。

【问题讨论】:

  • 如果删除模板中的样式属性会怎样?如果可行,也许您可​​以使用类(css),这是一种更好的方法:)。如果这些再次让 IE 失控,也许 dataTables 中有一个 oncompleted 事件可以连接你并让你应用所需的 CSS
  • 您可以尝试从更新面板中删除Triggers 部分。由于ChildrenAsTriggers默认为trueddlProductsSector已经是一个异步回发触发器。
  • 您也可以使用add_pageLoaded 代替add_endRequest 来设置bindTopProductsTable 事件处理程序。每次刷新 UpdatePanel 时都会执行
  • 触发器已删除,但不起作用。尝试添加到更新面板,但这也不起作用。我没有提到这是在 Sharepoint webpart 中,我认为在初始提交后有一些东西会影响页面。
  • 想通了,我的答案在这里:stackoverflow.com/questions/7749393/…

标签: javascript c# jquery asp.net


【解决方案1】:

我想通了。事实证明,Sharepoint 有一个标志来防止某人单击按钮两次。我添加了这段代码:

function setFormSubmitToFalse() {
    setTimeout(function () { _spFormOnSubmitCalled = false; }, 3000);
    return true;
}

现在可以正常使用了。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-01-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-12-20
    • 2017-11-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多