NPM Datatable Excel按钮未显示 [英] NPM Datatable Excel button not showing

查看:97
本文介绍了NPM Datatable Excel按钮未显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的 Excel 按钮现在显示.我正在使用NPM导入所有脚本,所有其他按钮都可以正常使用( PDF,复制,打印).只有 Excel 无效.

My Excel Button in datatable is now showing up. I'm using NPM to import all scripts, all others buttons works well (PDF, Copy, Print). Only Excel do not work.

检查我的进口商品:

import 'datatables.net-bs'
import 'datatables.net-buttons-bs'
import 'datatables.net-responsive-bs'
import 'datatables.net-buttons/js/buttons.colVis.js'
import 'datatables.net-buttons/js/buttons.flash.js'
import 'jszip'
import pdfMake from 'pdfmake/build/pdfmake'
import pdfFonts from 'pdfmake/build/vfs_fonts'
import 'datatables.net-buttons/js/buttons.html5.js'
import 'datatables.net-buttons/js/buttons.print.js'

pdfMake.vfs = pdfFonts.pdfMake.vfs

我的配置:

let datatableConfig = {
    responsive: true,
    "dom": '<"html5buttons"B>lTfgtip',
    "buttons": [
        { extend: 'copy' },
        { extend: 'excel'}, 
        { extend: 'excelHtml5' },
        { extend: 'pdf'  },
        { extend: 'print' }
    ]
};

$('#dataTable').DataTable(datatableConfig)

如果我将https://cdnjs.cloudflare.com/ajax/libs/jszip/3.1.4/jszip.min.js直接放在HTML中,则可以正常工作.使用import如何不起作用? (是的,已经安装了jszip)

If i put https://cdnjs.cloudflare.com/ajax/libs/jszip/3.1.4/jszip.min.js direct in my HTML, it works. How it do not work using import? (Yes, jszip is already installed)

谢谢!

推荐答案

我在require语法上遇到了同样的问题,我不得不这样做:

I got the same issue with the require syntax and I had to do :

window.JSZip = require( "jszip" );

我不知道import的语法,但也许有点像

I don't know the syntax with import but maybe it's something like

import window.JSZip from 'jszip';

JSZip from 'jszip';

import JSZip from 'jszip';
window.JSZip = JSZip;

这篇关于NPM Datatable Excel按钮未显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆