MudMenu does not work correctly with MudTable

I want to use MudMenu as a context menu for MudTable. After several attempts, I found two cases where MudMenu works but still has issues:

Case 1: MudMenu is placed inside , with surrounding the columns. MudMenu works correctly, opening the menu at the row position of the mouse cursor. However, the columns become distorted and no longer align with the header, and the rows do not align correctly between diffirent rows:

<MudTable Class="mt-3" Dense Bordered Height="465px"
            ReadOnly="false" HeaderClass="pa-1" Items="dt.Select()"
            T="DataRow" MultiSelection="false" RowClass="pa-0 cursor-pointer" Hover="true" Breakpoint="Breakpoint.None">
    <ToolBarContent>
        <MudText Typo="Typo.h6">Test table</MudText>
    </ToolBarContent>
    <HeaderContent>
        <MudTh Style="text-align:center; white-space:nowrap;"> Date </MudTh>
        <MudTh Style="text-align:center; white-space:nowrap;"> Name </MudTh>
        <MudTh Style="text-align:center; white-space:nowrap;"> ID </MudTh>
        <MudTh></MudTh>
    </HeaderContent>  
    <RowTemplate>
        <MudMenu PositionAtCursor="true" ActivationEvent="MouseEvent.RightClick">
            <ActivatorContent>
                <MudTd DataLabel="Date"> @(DateTime.Parse(context["Date"].ToString()).ToString("dd/MM/yyyy"))</MudTd>
                <MudTd DataLabel="Name"> @context["Name"].ToString()</MudTd>
                <MudTd DataLabel="ID" Style="padding:9px"> @context["ID"].ToString()</MudTd>
            </ActivatorContent>
            <ChildContent>
                <MudMenuItem>Open Menu</MudMenuItem>
            </ChildContent>
        </MudMenu>     
    </RowTemplate>    
</MudTable>

Case 2: MudMenu is placed outside MudTable, with surrounding the entire table. MudMenu works, and the table looks fine, but the menu opens in a different position from the mouse cursor, often outside the table content area:

<MudMenu PositionAtCursor="true" ActivationEvent="MouseEvent.RightClick">
    <ActivatorContent>
        <MudTable Class="mt-3" Dense Bordered Height="465px"
                    ReadOnly="false" HeaderClass="pa-1" Items="dt.Select()"
                    T="DataRow" MultiSelection="false" RowClass="pa-0 cursor-pointer" Hover="true" Breakpoint="Breakpoint.None">
            <ToolBarContent>
                <MudText Typo="Typo.h6">Test table</MudText>
            </ToolBarContent>
            <HeaderContent>
                <MudTh Style="text-align:center; white-space:nowrap;"> Date </MudTh>
                <MudTh Style="text-align:center; white-space:nowrap;"> Name </MudTh>
                <MudTh Style="text-align:center; white-space:nowrap;"> ID </MudTh>
                <MudTh></MudTh>
            </HeaderContent>
            
            <RowTemplate>
                <MudTd DataLabel="Date"> @(DateTime.Parse(context["Date"].ToString()).ToString("dd/MM/yyyy"))</MudTd>
                <MudTd DataLabel="Name"> @context["Name"].ToString()</MudTd>
                <MudTd DataLabel="ID" Style="padding:9px"> @context["ID"].ToString()</MudTd>            
            </RowTemplate>    
        </MudTable>
    </ActivatorContent>
    <ChildContent>
        <MudMenuItem>Open Menu</MudMenuItem>
    </ChildContent>
</MudMenu>  

How can I fix these issues? Is there another way to create a context menu in this scenario?

The problem is, that the Element MudTd has only the correct layout as Cell if it’s a direct child of RowTemplate. That’s why for your second case the layout works.

You have to define a MudMenu for each cell. (I don’t think there’s a way around but, but hopefully someone knows how to).

<RowTemplate>
    <MudTd DataLabel="Date">
        <MudMenu PositionAtCursor="true" ActivationEvent="MouseEvent.RightClick" Style="@MenuStyle()">
            <ActivatorContent>
                @context.Name
            </ActivatorContent>
            <ChildContent>
                <MudMenuChildContent />
            </ChildContent>
        </MudMenu>  
    </MudTd>   
    <MudTd DataLabel="Number" Style="@CellStyle()">
        <MudMenu PositionAtCursor="true" ActivationEvent="MouseEvent.RightClick" Style="@MenuStyle()">
            <ActivatorContent>
                @context.Number
            </ActivatorContent>
            <ChildContent>
                <MudMenuChildContent />
            </ChildContent>
        </MudMenu>  
    </MudTd>  
    <MudTd DataLabel="Position" Style="@CellStyle()">
        <MudMenu PositionAtCursor="true" ActivationEvent="MouseEvent.RightClick" Style="@MenuStyle()">
            <ActivatorContent>
                @context.Position
            </ActivatorContent>
            <ChildContent>
                <MudMenuChildContent />
            </ChildContent>
        </MudMenu>  
    </MudTd>  
</RowTemplate> 

(For this example I used the items on Class Element, proved by the various MudBlazor examples)

Here’s a snippet: MudBlazor snippet

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật