Excel按钮问题在Safari使用数据表

Excel button issue in Safari using datatable

本文关键字:数据表 Safari 按钮 问题 Excel      更新时间:2023-09-26

我的按钮有问题,它允许将数据导出到。xlsx文件。它适用于Edge, Mozilla和Chrome,但如果我在iphone或Macbook上尝试Safari ,似乎按钮只是缺失和不可见。

这件事我真的需要帮助,因为我找不到一个合适的解决方案。数据导出应该完全工作在Safari, Mozilla, Edge, Chrome。

也许有人遇到过类似的问题?我的代码:

$(document).ready(function() {
var table = $('#tableOrders').DataTable( {
    "bFilter" : true,               
    "bLengthChange": true,
    "paging":   true,
    "ordering": true,
    "order": [[ @if ($user->role=='super_admin') 7 @else 6 @endif, "desc" ]],
    "info":true,
    dom: 'lBfrtip',
    lengthMenu: [
        [ 10, 25, 50, -1 ],
        [ '10', '25', '50', 'Show all' ]
    ],
    buttons: [
        {
            extend: 'copyHtml5',
            text: '<b>Copy all</b>',
            exportOptions: {
                columns: [@if($user->role=='super_admin') 0, 1, 2, 3, 4, 5, 6 @else 0, 1, 2, 3, 4 @endif]
            }
        },
        {
            extend: 'excelHtml5',
            text: 'Export all to <b>Excel</b>',
            exportOptions: {
                columns: [@if($user->role=='super_admin') 0, 1, 2, 3, 4, 5, 6 @else 0, 1, 2, 3, 4 @endif]
            }
        },
    ]
} );

});

excelHtml5按钮在Safari中不支持。文档中有关于它的说明(https://datatables.net/reference/button/excelHtml5):

)

Safari:不

Safari目前不支持下载生成文件的功能(参见WebKit bug 156056)。一旦在Safari中解决了这个问题,它就会在这里发布。

试着在Safari中打开他们的演示:https://datatables.net/extensions/buttons/examples/initialisation/export.html你不会在Safari中看到Excel按钮。

此外,根据论坛讨论(https://datatables.net/forums/discussion/30444/datatables-built-in-buttons-not-working-with-safari-browser) csv按钮在Safari中支持有限。打开带有生成的csv的新选项卡。

面临同样的问题,如上所述它是不支持的。但是,如果希望在浏览器之间保持完整性,可以通过safari的user-agent进行验证,并将字符串传递给变量。因为CSV可以在Safari上工作。

 var xls; // variable csv ó excel
    (navigator.userAgent.indexOf('Safari') != -1 && navigator.userAgent.indexOf('Chrome') == -1) ? xls = 'csv' : xls = 'excel'; //verify

则扩展:

  extend: xls, title: 'yourtitle', className: "btn-sm"

最新版本的Datatables.Buttons可以在Safari中运行