Browse Source

Merge pull request #6575 from wenzhixin/feature/6524

Persist custom data attributes for the header
Dustin Utecht 3 years ago
parent
commit
e7a298a3bd
1 changed files with 17 additions and 0 deletions
  1. 17 0
      src/bootstrap-table.js

+ 17 - 0
src/bootstrap-table.js

@@ -180,7 +180,16 @@ class BootstrapTable {
         if (typeof $th.data('field') !== 'undefined') {
           $th.data('field', `${$th.data('field')}`)
         }
+        const _data = Object.assign({}, Utils.getRealDataAttr($th.data()))
+
+        for (const key in _data) {
+          if ($.fn.bootstrapTable.columnDefaults.hasOwnProperty(key)) {
+            delete _data[key]
+          }
+        }
+
         column.push(Utils.extend({}, {
+          _data,
           title: $th.html(),
           class: $th.attr('class'),
           titleTooltip: $th.attr('title'),
@@ -305,6 +314,7 @@ class BootstrapTable {
 
         const headerStyle = Utils.calculateObjectValue(null, this.options.headerStyle, [column])
         const csses = []
+        const data_ = []
         let classes = ''
 
         if (headerStyle && headerStyle.css) {
@@ -340,6 +350,12 @@ class BootstrapTable {
           visibleColumns[column.field] = column
         }
 
+        if (Object.keys(column._data || {}).length > 0) {
+          for (const [k, v] of Object.entries(column._data)) {
+            data_.push(`data-${k}='${typeof v === 'object' ? JSON.stringify(v) : v}'`)
+          }
+        }
+
         html.push(`<th${Utils.sprintf(' title="%s"', column.titleTooltip)}`,
           column.checkbox || column.radio ?
             Utils.sprintf(' class="bs-checkbox %s"', column['class'] || '') :
@@ -350,6 +366,7 @@ class BootstrapTable {
           Utils.sprintf(' data-field="%s"', column.field),
           // If `column` is not the first element of `this.options.columns[0]`, then className 'data-not-first-th' should be added.
           j === 0 && i > 0 ? ' data-not-first-th' : '',
+          data_.length > 0 ? data_.join(' ') : '',
           '>')
 
         html.push(Utils.sprintf('<div class="th-inner %s">',