jQuery 数据表按钮错误:未捕获的未知按钮类型:打印

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/36401295/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 17:05:31  来源:igfitidea点击:

Datatable Button Error: Uncaught Unknown button type: print

jqueryruby-on-railsdatatablesasset-pipeline

提问by Felix Letkemann

I've got a very strange problem with the print button on a datatable I couldn't find a solution for.

我在数据表上的打印按钮有一个非常奇怪的问题,我找不到解决方案。

The strange thing is that I've already used the print button in datatables on different pages.

奇怪的是,我已经在不同页面的数据表中使用了打印按钮。

At the moment I am working on a ruby on rails project, including datatables with the jquery-datatables-rails gem, version 3.3.0.

目前我正在开发一个 ruby​​ on rails 项目,包括带有 jquery-datatables-rails gem 版本 3.3.0 的数据表。

Additionally, I include the CSS and the JS file for the buttons by referencing the file path in the assets pipeline (dataTables.buttons.minand buttons.datatables.min.css).

此外,我通过引用资产管道(dataTables.buttons.minbuttons.datatables.min.css)中的文件路径来包含按钮的 CSS 和 JS 文件。

All the files are loaded without any problem or error message. Initialising of the datatable works as well, but then I add the option below:

加载所有文件都没有任何问题或错误消息。数据表的初始化也有效,但随后我添加了以下选项:

dom: 'Bfrtip'
buttons: [ 'print' ]

to the initializer, it causes to crash with the error message below:

到初始化程序,它会导致崩溃并显示以下错误消息:

Uncaught Unknown button type: print dataTables.buttons.min.js?body=1:18

未捕获的未知按钮类型:打印 dataTables.buttons.min.js?body=1:18

Unfortunately I could not find anyone that has the same problem in the internet.

不幸的是,我在互联网上找不到任何有同样问题的人。

I followed the instructions on https://datatables.net/extensions/buttons/, adding the two files to my page.

我按照https://datatables.net/extensions/buttons/上的说明,将这两个文件添加到我的页面。

Also, when I try to use the excelbutton instead of the printbutton, no error message appears, but still no button is showing up.

此外,当我尝试使用excel按钮而不是打印按钮时,没有出现错误消息,但仍然没有显示任何按钮。

The div.dt-buttonsstays empty.

div.dt-buttons保持空。

How can I resolve this?

我该如何解决这个问题?

回答by Gaurav

You need to include this file :

您需要包含此文件:

//cdn.datatables.net/buttons/1.2.1/js/buttons.print.min.js

For other issues like Excel as well, related asset files may be missing in your case. Check the list of JS files included in this example for reference.

对于 Excel 等其他问题,您的案例中可能缺少相关资产文件。检查本示例中包含的 JS 文件列表以供参考。

https://datatables.net/extensions/buttons/examples/initialisation/export.html

https://datatables.net/extensions/buttons/examples/initialisation/export.html

List is given in Javascript tab of the example.

列表在示例的 Javascript 选项卡中给出。

回答by born4new

I believe you have to include the print button extensionin your page.

我相信您必须在页面中包含打印按钮扩展名

From the docs:

文档

These buttons are not part of the core library, but rather are individual files that can be included as you require. For example you may with to provide HTML5 file export buttons but not Flash export buttons. This simply ensures that only the code you require is delivered to the end user.

这些按钮不是核心库的一部分,而是可以根据需要包含的单个文件。例如,您可以提供 HTML5 文件导出按钮而不是 Flash 导出按钮。这只是确保仅将您需要的代码交付给最终用户。