浏览代码

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 `sortBy` method.
 - **New:** Added `switchableLabel` column option.
 - **New:** Added `switchableLabel` column option.
+- **Update** Added support for `class` attribute in toolbar buttons.
 
 
 #### Extensions
 #### Extensions
 
 

+ 9 - 1
src/bootstrap-table.js

@@ -746,10 +746,18 @@ class BootstrapTable {
           buttonHtml = buttonConfig.html
           buttonHtml = buttonConfig.html
         }
         }
       } else {
       } 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')) {
         if (buttonConfig.hasOwnProperty('attributes')) {
           for (const [attributeName, value] of Object.entries(buttonConfig.attributes)) {
           for (const [attributeName, value] of Object.entries(buttonConfig.attributes)) {
+            if (attributeName === 'class') {
+              continue
+            }
             buttonHtml += ` ${attributeName}="${value}"`
             buttonHtml += ` ${attributeName}="${value}"`
           }
           }
         }
         }