简体   繁体   English

jquery 数据表在 Firefox 中不起作用

[英]jquery datatable not working in firefox

I use the below code我使用下面的代码

 $("body").html(tab).promise().done(function () {

            $('table').DataTable({
                initComplete: function () {
                    $('.buttons-excel').click()
                },
                paging: false,
                columnDefs: [{
                    targets: 'no-sort',
                    orderable: false
                }],

                dom: 'Bfrtip',
                fixedHeader: {
                    header: true
                },
                buttons: {
                    extend: 'excelHtml5',
                    customize: function( xlsx ) {
                        var sheet = xlsx.xl.worksheets['sheet1.xml'];

                        $('row c[r^="C"]', sheet).attr( 's', '2' );
                    },
                    buttons: [{
                        extend: 'excel',
                        text: '<i class="fa fa-print"></i> excel',
                        title: filename,
                        exportOptions: {
                            columns: ':not(.no-print)'
                        }
                    }],
                    dom: {
                        container: {
                            className: 'dt-buttons'
                        },
                        button: {
                            className: 'btn btn-default'
                        }
                    }
                }
            });
 });

This works fine in Chrome and IE这在 Chrome 和 IE 中运行良好

But in firefox, i get the below error但是在 Firefox 中,我收到以下错误

not well-formed (unknown)格式不正确(未知)

Some background about the code:关于代码的一些背景:

The page is loaded inside iFrame页面在 iFrame 内加载

There will be only one table inside this page that uses jquery datatable此页面中将只有一个表使用 jquery 数据表

The page will automatically trigger click of excel to start downloading页面会自动触发点击excel开始下载

I have read in few questions on SO that states that we should change MIME type for ajax calls, but here we have No ajax calls made, as the table will be loaded on pageload in server side code我已经阅读了一些关于 SO 的问题,其中指出我们应该更改 ajax 调用的 MIME 类型,但在这里我们没有进行 ajax 调用,因为该表将在服务器端代码的页面加载时加载

make sure you have followed HTML structure of table.确保您遵循表格的 HTML 结构。

  1. Well defined tabel start and end tag.定义良好的表格开始和结束标签。
  2. for header line make sure you have defined structure like this <thead><tr><th>...</th><th>...</th>...</tr></thead>对于标题行,请确保您已经定义了这样的结构<thead><tr><th>...</th><th>...</th>...</tr></thead>

  3. for all data record row make sure you have defined structure like this <tbody><tr><td>...</td><td>...</td></tr></tbody>对于所有数据记录行,请确保您已经定义了这样的结构<tbody><tr><td>...</td><td>...</td></tr></tbody>

  4. Number of column in each row must be equal.每行中的列数必须相等。

  5. If you have footer line make sure you have defined structure like this <tfoot><tr><td>...</td><td>...</td></tr></tfoot>如果您有页脚行,请确保您已经定义了这样的结构<tfoot><tr><td>...</td><td>...</td></tr></tfoot>

This is wierd这很奇怪

Turns out that Firefox is not allowing downloads from an iFrame if its hidden事实证明 Firefox 不允许从 iFrame 下载,如果它是隐藏的

Previously the code was以前的代码是

  <iframe id="iframeFile" runat="server" style="display:none"></iframe>

Then I tried changing it to然后我尝试将其更改为

  <iframe id="iframeFile" runat="server" style="width:0;height:0;overflow:hidden"></iframe>

it all started working!这一切都开始工作了! wierd怪异的

PS: if someone can add information on how this worked in comments section, that would help people who read this in future PS:如果有人可以在评论部分添加有关这是如何工作的信息,那将有助于将来阅读此内容的人

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM