ソースを参照

Merge pull request #6829 from marceloverdijk/feature/button-class-attribute3

Added support for `class` attribute in toolbar buttons.
Dustin Utecht 2 年 前
コミット
a0451aa5fe
2 ファイル変更10 行追加1 行削除
  1. 1 0
      CHANGELOG.md
  2. 9 1
      src/bootstrap-table.js

+ 1 - 0
CHANGELOG.md

@@ -7,6 +7,7 @@ ChangeLog
 
 - **New:** Added `sortBy` method.
 - **New:** Added `switchableLabel` column option.
+- **Update** Added support for `class` attribute in toolbar buttons.
 
 #### Extensions
 

+ 9 - 1
src/bootstrap-table.js

@@ -746,10 +746,18 @@ class BootstrapTable {
           buttonHtml = buttonConfig.html
         }
       } else {
-        buttonHtml = `<button class="${this.constants.buttonsClass}" type="button" name="${buttonName}"`
+        let buttonClass = this.constants.buttonsClass
+
+        if (buttonConfig.hasOwnProperty('attributes') && buttonConfig.attributes.class) {
+          buttonClass += ` ${buttonConfig.attributes.class}`
+        }
+        buttonHtml = `<button class="${buttonClass}" type="button" name="${buttonName}"`
 
         if (buttonConfig.hasOwnProperty('attributes')) {
           for (const [attributeName, value] of Object.entries(buttonConfig.attributes)) {
+            if (attributeName === 'class') {
+              continue
+            }
             buttonHtml += ` ${attributeName}="${value}"`
           }
         }