We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Using $emit from child to parent without EventBus

Hi Syncfusion,

I have the following structure in a SFC:
  • A Syncfusion Grid with a custom toolbar defined like this: https://www.screencast.com/t/kUfGfLyhWUA
  • The template GridToolbar.vue has button to test emit like this: https://www.screencast.com/t/y13KcPsUlBU
  • And then the method to emit to parent component: https://www.screencast.com/t/zJvaoIfIrV
The problem seems to be that the grid with the custom toolbar is not in the scope of a VueComponent so when emitting from the toolbar there is no parent component to receive the emitted event. 

I cannot use a global EventBus because I have multiple grids in the single file application and need event sent only from a specific child to that childs parent. 

How can I use standard Vue $emit feature between a Grid with custom Toolbar to it's parent component? 

Thanks,
Marius

1 Reply

TS Thavasianand Sankaranarayanan Syncfusion Team October 30, 2019 10:14 AM UTC

Hi Marius, 
 
Greetings from Syncfusion support.  

We checked your reported query and provided code snippets and based on that we suggest you to use custom item in toolbar instead of custom toolbar to achieve your requirement. Since the toolbar is rendered as a separate component and then appended inside the grid, the parent element is not returned. On using custom toolbar item, you will get the parent element in the toolbar click event where you can use the $emit vue feature. 

This is demonstrated in below code snippet, 

<ejs-grid id="Grid" :toolbar="toolbar" :toolbarClick="clickHandler" :dataSource="data" :allowPaging="true" ref="grid"></ejs-grid> 
 
<script> 
export default { 
   data() { 
      return { 
        toolbar: [ 
          { text: "Emit", tooltipText: "Click", id: "emit" }, 
          { text: "New view", tooltipText: "New view", id: "newView" } 
        ] 
      }; 
    }, 
    methods: { 
      clickHandler: function (args) { 
        if (args.item.id === "emit") { 
          this.$emit("propValue", "prop"); 
        } 
      } 
    }, 
} 
</script> 

We have prepared a sample for your reference. You can find it below, 

 
Regards, 
Thavasianand S. 


Loader.
Up arrow icon