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

How to use a Vue component with detailFormatter #4754

Closed
stevespringett opened this issue Dec 18, 2019 · 2 comments
Closed

How to use a Vue component with detailFormatter #4754

stevespringett opened this issue Dec 18, 2019 · 2 comments
Labels
awaiting reply Issues that are awaiting reply, will be closed if there is no any response in 7 days. help-wanted Issues we need or would love help from the community to resolve.

Comments

@stevespringett
Copy link

stevespringett commented Dec 18, 2019

Hello. I'm trying to use a Vue component with detailFormatter. The idea is that a user would click a row, which would then expand, and a normal Vue component would be displayed.

I have tried to programmatically instantiate a Vue component and render out the HTML. This works, but it lacks the interactivity of a Vue component. So it's fine for static content, but not for dynamic.

I took a look at the mixin here: https://github.com/wenzhixin/bootstrap-table-examples/blob/develop/vue-starter/src/mixins/table.js and the blog from https://blog.bootstrap-table.com/2019/08/10/formatter-use-vue-component/ but these do not appear to work with detailFormatters.

Any idea how I can get this to work?

This works for static data:

detailFormatter: function (index, row) {
  // Programmatically instantiate MyComponent Vue component
  let ComponentClass = Vue.extend(MyComponent);
  let component = new ComponentClass({
    propsData: {
      myData: row
    }
  });
  component.$mount();
  return component.$el.outerHTML;
},

However, because it's static, the data from the row is never rendered, nor can it change over time.

Ideally, what I'd like to have is:

detailFormatter: function (index, row) {
  return this.vueFormatter({
    template: '<my-component :my-data="row" />',
    data: { row },
  })
}

And have the component be reactive like every other Vue component. Any idea how I can achieve this?

@wenzhixin
Copy link
Owner

@wenzhixin wenzhixin added awaiting reply Issues that are awaiting reply, will be closed if there is no any response in 7 days. help-wanted Issues we need or would love help from the community to resolve. labels Dec 20, 2019
@stevespringett
Copy link
Author

Fantastic. Exactly what I was looking for. Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting reply Issues that are awaiting reply, will be closed if there is no any response in 7 days. help-wanted Issues we need or would love help from the community to resolve.
Projects
None yet
Development

No branches or pull requests

2 participants