Browse Source

added an option to force hide a column while exporting

NAME 5 years ago
parent
commit
7ff24c1721
2 changed files with 26 additions and 1 deletions
  1. 12 0
      site/docs/extensions/export.md
  2. 14 1
      src/extensions/export/bootstrap-table-export.js

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

@@ -110,6 +110,18 @@ This is an important link to check out as some file types may require extra step
 
 - **Default:** `false`
 
+### forceHide
+
+- **Attribute:** `data-force-hide`
+
+- **type:** `Boolean`
+
+- **Detail:**
+
+   Set `true` to force hide a column e.g. for icon columns.
+
+- **Default:** `false`
+
 ## Events
 
 ### onExportSaved

+ 14 - 1
src/extensions/export/bootstrap-table-export.js

@@ -36,7 +36,8 @@ $.extend($.fn.bootstrapTable.defaults, {
 })
 
 $.extend($.fn.bootstrapTable.columnDefaults, {
-  forceExport: false
+  forceExport: false,
+  forceHide: false
 })
 
 $.extend($.fn.bootstrapTable.defaults.icons, {
@@ -184,6 +185,12 @@ $.BootstrapTable = class extends $.BootstrapTable {
         this.toggleView()
       }
 
+      this.columns.forEach((row) => {
+        if (row.forceHide) {
+          this.hideColumn(row.field)
+        }
+      })
+
       const data = this.getData()
       if (o.exportFooter) {
         const $footerRow = this.$tableFooter.find('tr').first()
@@ -235,6 +242,12 @@ $.BootstrapTable = class extends $.BootstrapTable {
             }
           })
 
+          this.columns.forEach((row) => {
+            if (row.forceHide) {
+              this.showColumn(row.field)
+            }
+          })
+
           if (callback) callback()
         }
       }, o.exportOptions, options))