Blazor Grid: How to disable context menu items based on clicked cell?

How do disable context menu items?

        public void ContextMenuOpened(ContextMenuOpenEventArgs<DeliveryNote> args)
        {
            foreach (var item in args.Items)
            {
                if (item.Id == "edit" && !args.Column.AllowEditing)
                {
                    item.Disable = false; //does not work
                    item.Hidden = false; //does not work
                }
            }
        }

I'm using     <PackageReference Include="Syncfusion.Blazor" Version="18.3.0.47" />

3 Replies 1 reply marked as answer

RS Renjith Singh Rajendran Syncfusion Team November 12, 2020 08:49 AM UTC

Hi Liero, 

Greetings from Syncfusion support. 

We suggest you to modify the Disabled property value in args.ContextMenuObj to achieve this requirement. Please refer and use the below codes to achieve this requirement. 

 
public void ContextMenuOpened(ContextMenuOpenEventArgs<Order> args) 
{ 
    foreach (var item in args.Items) 
    { 
        if (item.Id == "edit" && !args.Column.AllowEditing) 
        { 
            args.ContextMenuObj.Items[0].Disabled = true; 
        } 
        else if(item.Id == "edit" && args.Column.AllowEditing) 
        { 
            args.ContextMenuObj.Items[0].Disabled = false; 
        } 
    } 
} 


Please get back to us if you need further assistance. 

Regards, 
Renjith Singh Rajendran 


Marked as answer

LI Liero November 12, 2020 11:05 AM UTC

Thanks. It works, but I'm getting: BL0005:Component parameter should not be set outside of its component.


RN Rahul Narayanasamy Syncfusion Team November 13, 2020 03:44 AM UTC

Hi Liero, 

Thanks for the update. 

Query: It works, but I'm getting: BL0005:Component parameter should not be set outside of its component. 

We have validated your query and you can resolve the warning by using below codes. Find the below code snippets for your reference. 



public void ContextMenuOpened(ContextMenuOpenEventArgs<Order> args)  
{  
#pragma warning disable BL0005    // you can resolve the warning by using this 
 
    foreach (var item in args.Items)  
    {  
        if (item.Id == "edit" && !args.Column.AllowEditing)  
        {  
            args.ContextMenuObj.Items[0].Disabled = true;  
        }  
        else if(item.Id == "edit" && args.Column.AllowEditing)  
        {  
            args.ContextMenuObj.Items[0].Disabled = false;  
        }  
    }  
#pragma warning restore BL0005      // you can resolve the warning by using this 
 
}  


Please let us know if you have any concerns. 

Regards, 
Rahul 


Loader.
Up arrow icon