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. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Using $emit from child to parent without EventBus

Thread ID:

Created:

Updated:

Platform:

Replies:

148642 Oct 29,2019 04:34 AM UTC Oct 30,2019 10:14 AM UTC Vue 1
loading
Tags: Data Grid
Marius Lian
Asked On October 29, 2019 04:34 AM UTC

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

Thavasianand Sankaranarayanan [Syncfusion]
Replied On 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. 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon