javascript Bootstrap-table 如何使用 exportOptions

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/32926684/
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-10-28 15:55:55  来源:igfitidea点击:

Bootstrap-table how to use exportOptions

javascriptbootstrap-table

提问by user1534019

I want to change the filename that is used when using the Table Export extension. I know I can use the exportOptions to add {fileName:'custom_file_name'}. But I don't know where to put this.

我想更改使用表导出扩展时使用的文件名。我知道我可以使用 exportOptions 添加 {fileName:'custom_file_name'}。但我不知道把这个放在哪里。

I tried:

我试过:

data-export-options="{fileName:'custom_file_name'}"

and I tried to add as a method:

我尝试添加为一种方法:

$('#table').bootstrapTable('exportOptions', {fileName: 'custom_file_name'})

But then I get an error: Uncaught Error: Unknown method: exportOptionsenter code here

但后来我收到一个错误:未捕获的错误:未知方法:exportOptionsenter code here

What am I missing?

我错过了什么?

回答by wenyi

Use like this:

像这样使用:

$('#table').bootstrapTable({
    exportOptions: {
        fileName: 'custom_file_name'
    }
});

Now we do not support via data-attributes, docs: http://bootstrap-table.wenzhixin.net.cn/extensions/#table-export.

现在我们不支持通过数据属性,文档:http: //bootstrap-table.wenzhixin.net.cn/extensions/#table-export

Example: http://jsfiddle.net/wenyi/e3nk137y/3365/

示例:http: //jsfiddle.net/wenyi/e3nk137y/3365/

回答by Timmy

You can add the following as a html table attribute:

您可以将以下内容添加为 html 表格属性:

data-export-options='{"fileName": "desired filename here"}'

Make sure you have the proper quotes and that the key is fileName with camelCase.

确保您有正确的引号,并且键是带有驼峰大小写的文件名。

回答by Mark Lohr

You can modify the default file name (tableExport) in the 'tableExport.js' file.

您可以在“tableExport.js”文件中修改默认文件名(tableExport)。

(function ($) {
  $.fn.extend({
    tableExport: function (options) {
      var defaults = {
        consoleLog: false,
        csvEnclosure: '"',
        csvSeparator: ',',
        csvUseBOM: true,
        displayTableName: false,
        escape: false,
        excelstyles: ['border-bottom', 'border-top', 'border-left', 'border-right'],
        fileName: 'Whatever_You_Like',
        htmlContent: false,
        ignoreColumn: [],
        ignoreRow:[],
        jspdf: {orientation: 'p',

回答by Garrett Fogerlie

You can't have showExport in the table tag, it needs to be in the javascript like this:

你不能在 table 标签中有 showExport,它需要像这样在 javascript 中:

$(function () {
    $('#table').bootstrapTable({
        data: data,
        showExport: true,
        exportOptions: {
            fileName: 'some_file_name'
        }
    });
});

回答by Peter Zemljic

If you prefer to create the rest of your table via data attributes, you can use the refreshOptions method:

如果您更喜欢通过数据属性创建表的其余部分,您可以使用 refreshOptions 方法:

$('#table').bootstrapTable('refreshOptions', {exportOptions: {fileName: 'custom_file_name'}});