Bootstrap-table how to use exportOptions
Asked Answered
R

5

6

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.

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

What am I missing?

Runck answered 3/10, 2015 at 19:34 Comment(0)
L
7

You can add the following as a html table attribute:

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

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

Longanimity answered 22/5, 2020 at 13:53 Comment(0)
I
6

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.

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

Isom answered 13/10, 2015 at 7:27 Comment(1)
I tried the code, but it doesn't work. The file is still exported as tableExport. The code is executed by javascript.Runck
F
0

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

(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',
Fredella answered 4/12, 2015 at 16:0 Comment(0)
L
0

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

$(function () {
    $('#table').bootstrapTable({
        data: data,
        showExport: true,
        exportOptions: {
            fileName: 'some_file_name'
        }
    });
});
Loleta answered 6/3, 2016 at 22:45 Comment(0)
M
0

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

$('#table').bootstrapTable('refreshOptions', {exportOptions: {fileName: 'custom_file_name'}});
Marianmariana answered 5/4, 2020 at 3:2 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.