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

Disable custom toolbar buttons and conext menu item if no element is selected

Thread ID:

Created:

Updated:

Platform:

Replies:

144434 May 6,2019 02:58 PM UTC May 8,2019 10:59 AM UTC Vue 1
loading
Tags: Data Grid
Chris
Asked On May 6, 2019 02:58 PM UTC

I have custom buttons in the datagrid toolbar and in the conext menu.

How can I disable them if no entry in the grid is selected? Normally i would do sth like: :disabled="_.isEmpty(this.selectedRows)", but since they are generated automatically I don't know how to do that.

gridContextMenuItems: [
{
text: 'Copy Url',
target: '.e-content',
id: 'copyurl'
}],

toolbarOptions: [
{
text: 'Copy url',
id: 'copyurl'
}]

Pavithra Subramaniyam [Syncfusion]
Replied On May 8, 2019 10:59 AM UTC

 
Thanks for contacting Syncfusion support. 
 
From your query we found that you want to enable and disable the Grid toolbar and contextMenu items based on the Grid row selection. So we suggest to use the Grid rowSelected and rowDeselected event to achieve this requirement. Please refer the following code snippet, 
 
rowSelected: function(args) { 
        if (this.$refs.grid.getSelectedRecords().length) { 
            this.$refs.grid.ej2Instances.toolbarModule.enableItems(["copyurl"], true);           this.$refs.grid.ej2Instances.contextMenuModule.contextMenu.enableItems(['Copy Url'], true); 
        } 
    }, 
rowDeselected: function(args) { 
        if (!this.$refs.grid.getSelectedRecords().length) { 
            this.$refs.grid.ej2Instances.toolbarModule.enableItems(["copyurl"], false); 
            this.$refs.grid.ej2Instances.contextMenuModule.contextMenu.enableItems(['Copy Url'], false); 
        } 
    } 
 
In the above code, we have used enableItems method of the contextMenu and Toolbar controls to achieve this requirement. We have prepared the sample for your reference and you can find that sample from the below link, 
 
 
                              https://ej2.syncfusion.com/vue/documentation/api/grid/#rowdeselected 
                              https://ej2.syncfusion.com/vue/documentation/api/toolbar#enableitems 
                              https://ej2.syncfusion.com/vue/documentation/api/context-menu#enableitems 
 
Regards, 
Pavithra 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