Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Supports column formatter options returns dom element or jquery element #7444

Merged
merged 2 commits into from
Aug 7, 2024

Conversation

weibangtuo
Copy link

@weibangtuo weibangtuo commented Aug 1, 2024

🤔Type of Request

  • Bug fix
  • New feature
  • Improvement
  • Documentation
  • Other

🔗Resolves an issue?

📝Changelog

  • Core
  • Extensions

💡Example(s)?

Example online

Code example

$('#table').bootstrapTable({
  columns: [
    {
      field: 'html',
      title: 'HTML',
      formatter: val => {
        const div = document.createElement('div')
  
        div.append('html')
        div.addEventListener('click', () => { alert('From html') })
        return div
      }
    },
    {
      field: 'jquery',
      title: 'jQuery',
      formatter: val => {
        const div = $('<div>')
  
        div.html('jquery')
        div.on('click', () => { alert('From jquery') })
        return div
      }
    },
    {
      field: 'vue3',
      title: 'Vue3 Component',
      formatter: val => {
        // import { h, render, getCurrentInstance } from 'vue'
        // import MyComponent from './MyComponent.vue'

        const vnode = h(MyComponent, props, children)
        const app = this.$.appContext // or const app = getCurrentInstance().appContext.app
        const div = document.createElement('div')

        vnode.appContext = app
        render(vnode, div)
        return div
      }
    },
    {
      field: 'echart',
      title: 'EChart Example',
      formatter: val => {
        const chartDom = document.createElement('div')

        // Size needs to be set because DOM is not mounted immediate and size cannot be obtained.
        chartDom.style.width = '300px'
        chartDom.style.height = '200px'

        const myChart = echarts.init(chartDom)
  
        myChart.setOption({
          xAxis: {
            type: 'category',
            data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
          },
          yAxis: {
            type: 'value'
          },
          series: [
            {
              data: [150, 230, 224, 218, 135, 147, 260],
              type: 'line'
            }
          ]
        })
        return chartDom
      }
    },
  ]
})

☑️Self Check before Merge

⚠️ Please check all items below before reviewing. ⚠️

  • Doc is updated/provided or not needed
  • Demo is updated/provided or not needed
  • Changelog is provided or not needed

@wenzhixin wenzhixin self-requested a review August 1, 2024 07:53
@wenzhixin
Copy link
Owner

@wenzhixin
Copy link
Owner

vue + develop example: https://live.bootstrap-table.com/code/wenzhixin/18014

@weibangtuo
Copy link
Author

Updated, Examle Online: https://live.bootstrap-table.com/code/weibangtuo/18018

src/bootstrap-table.js Outdated Show resolved Hide resolved
@wenzhixin
Copy link
Owner

这个例子原来的写法失效了,帮忙修改下:
https://live.bootstrap-table.com/code/wenzhixin/18027

@wenzhixin wenzhixin merged commit 8b589b7 into wenzhixin:develop Aug 7, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants