Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
89 changes: 46 additions & 43 deletions src/bootstrap-table.js
Original file line number Diff line number Diff line change
Expand Up @@ -608,6 +608,51 @@ class BootstrapTable {
this.initBody()
}

renderButton (buttonName, buttonConfig) {
let buttonHtml

if (buttonConfig.hasOwnProperty('html')) {
if (typeof buttonConfig.html === 'function') {
buttonHtml = buttonConfig.html()
} else if (typeof buttonConfig.html === 'string') {
buttonHtml = buttonConfig.html
}
} else {
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
}

const attribute = attributeName === 'title' ?
this.options.buttonsAttributeTitle : attributeName

buttonHtml += ` ${attribute}="${value}"`
}
}

buttonHtml += '>'

if (opts.showButtonIcons && buttonConfig.hasOwnProperty('icon')) {
buttonHtml += `${Utils.sprintf(this.constants.html.icon, opts.iconsPrefix, buttonConfig.icon)} `
}

if (opts.showButtonText && buttonConfig.hasOwnProperty('text')) {
buttonHtml += buttonConfig.text
}

buttonHtml += '</button>'
}
return buttonHtml
}

initToolbar () {
const opts = this.options
let html = []
Expand Down Expand Up @@ -751,49 +796,7 @@ class BootstrapTable {
const buttonsHtml = {}

for (const [buttonName, buttonConfig] of Object.entries(this.buttons)) {
let buttonHtml

if (buttonConfig.hasOwnProperty('html')) {
if (typeof buttonConfig.html === 'function') {
buttonHtml = buttonConfig.html()
} else if (typeof buttonConfig.html === 'string') {
buttonHtml = buttonConfig.html
}
} else {
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
}

const attribute = attributeName === 'title' ?
this.options.buttonsAttributeTitle : attributeName

buttonHtml += ` ${attribute}="${value}"`
}
}

buttonHtml += '>'

if (opts.showButtonIcons && buttonConfig.hasOwnProperty('icon')) {
buttonHtml += `${Utils.sprintf(this.constants.html.icon, opts.iconsPrefix, buttonConfig.icon)} `
}

if (opts.showButtonText && buttonConfig.hasOwnProperty('text')) {
buttonHtml += buttonConfig.text
}

buttonHtml += '</button>'
}

buttonsHtml[buttonName] = buttonHtml
buttonsHtml[buttonName] = renderButton(buttonName, buttonConfig)
const optionName = `show${buttonName.charAt(0).toUpperCase()}${buttonName.substring(1)}`
const showOption = opts[optionName]

Expand Down