Browse Source

added an column option to force export columns e.g. hidden columns (#4419)

Dustin Utecht 6 years ago
parent
commit
a8027917bb
2 changed files with 31 additions and 2 deletions
  1. 12 0
      site/docs/extensions/export.md
  2. 19 2
      src/extensions/export/bootstrap-table-export.js

+ 12 - 0
site/docs/extensions/export.md

@@ -58,6 +58,18 @@ This is an important link to check out as some file types may require extra step
 
 - **Default:** `{}`
 
+## Column options
+
+### forceExport
+
+- **type:** `Boolean`
+
+- **Detail:**
+
+   Set `true` to force export a column e.g. hidden columns.
+
+- **Default:** `false`
+
 ## Events
 
 ### onExportSaved

+ 19 - 2
src/extensions/export/bootstrap-table-export.js

@@ -35,6 +35,10 @@ $.extend($.fn.bootstrapTable.defaults, {
   exportFooter: false
 })
 
+$.extend($.fn.bootstrapTable.columnDefaults, {
+  forceExport: false
+})
+
 $.extend($.fn.bootstrapTable.defaults.icons, {
   export: {
     bootstrap3: 'glyphicon-export icon-share',
@@ -89,8 +93,8 @@ $.BootstrapTable = class extends $.BootstrapTable {
       data-toggle="dropdown"
       type="button"
       title="${o.formatExport()}">
-      ${ o.showButtonIcons ? Utils.sprintf(this.constants.html.icon, o.iconsPrefix, o.icons.export) : ''}
-      ${ o.showButtonText ? o.formatExport() : ''}
+      ${o.showButtonIcons ? Utils.sprintf(this.constants.html.icon, o.iconsPrefix, o.icons.export) : ''}
+      ${o.showButtonText ? o.formatExport() : ''}
       ${this.constants.html.dropdownCaret}
       </button>
       </div>
@@ -183,6 +187,13 @@ $.BootstrapTable = class extends $.BootstrapTable {
         })
       }
 
+      const hiddenColumns = this.getHiddenColumns()
+      hiddenColumns.forEach((row) => {
+        if (row.forceExport) {
+          this.showColumn(row.field)
+        }
+      })
+
       this.$el.tableExport($.extend({
         onAfterSaveToFile: () => {
           if (o.exportFooter) {
@@ -196,6 +207,12 @@ $.BootstrapTable = class extends $.BootstrapTable {
             this.toggleView()
           }
 
+          hiddenColumns.forEach((row) => {
+            if (row.forceExport) {
+              this.hideColumn(row.field)
+            }
+          })
+
           if (callback) callback()
         }
       }, o.exportOptions, options))