stavroskasidis / BlazorContextMenu

A context menu component for Blazor !
MIT License
532 stars 58 forks source link

Disable menu item in table depending the model. #137

Closed Kris-I closed 11 months ago

Kris-I commented 1 year ago

Hello,

With MudBlazor, I have this :

<MudTable Items="Model.Datas" Hover="true" Elevation="0">
    <HeaderContent>
        <MudTh>Field 1</MudTh>
        <MudTh>Field 2</MudTh>
    </HeaderContent>
    <RowTemplate>
        <MudTd DataLabel="Name">
            <ContextMenuTrigger MenuId="myMenu" Data="@context.Id">
                @context.Name
            </ContextMenuTrigger>
        </MudTd>    
    </RowTemplate>
</MudTable>

<ContextMenu Id="myMenu">
    <Item OnClick="@OnClickType1">Action Type 1</Item>
    <Item OnClick="@OnClickType2">Action Type 2</Item>
</ContextMenu>

In the ContextMenuTrigger, I'd like disable one or several items ('Action Type 1' or/and 'Action Type 2') depending of @context.Item1Allowed

Is there a way to disable an or several items in the menu depending Is there a way to do it ?

Thanks,

stavroskasidis commented 1 year ago

I think you need the OnAppearing event. Please see the demo here (see how an item can be enabled/disabled or visible/hidden depending on context)

perlun commented 4 months ago

Thanks @stavroskasidis! This worked great for me too. :slightly_smiling_face: :+1: