I developed a context menu in Blazor with DevExpress to make a copy of selected record. For doing that I followed the DevExpress instructions:
The example has only the standard menu items of context menu, but I have only a custom item: "Copy Record". I think for this problem it make no difference because index is selected by clicking on grid.
The problem is it return the id of the record which is on top of the selected record is. with selected record I mean the record on which user is click on UI.
Code in list of data is:
<DxGrid @ref="_grid" Data="@Data" AllowSort="true" PageSize="15" ShowSearchBox="true" SearchBoxNullText="Suche" ShowFilterRow="true" ShowGroupPanel="true" AutoExpandAllGroupRows="true" ColumnResizeMode="GridColumnResizeMode.NextColumn" AllowSelectRowByClick="true" CustomizeElement="Grid_CustomizeElement" @oncontextmenu:preventDefault></DxGrid><GridContextMenuContainer Grid="_grid" @ref="ContextMenuContainer" />@code { private IGrid? _grid; GridContextMenuContainer ContextMenuContainer { get; set; } void Grid_CustomizeElement(GridCustomizeElementEventArgs e) { if (GridContextMenuHelper.IsContextMenuElement(e.ElementType)) { e.Attributes["oncontextmenu"] = EventCallback.Factory.Create<MouseEventArgs>( this, async mArgs => await ContextMenuContainer.Grid_ContextMenu(e, mArgs) ); } }}The code in ContextMenuContainer is:
<DxContextMenu @ref="RowContextMenu" Data="RowContextMenuData" ItemClick="RowContextMenu_ItemClick"><DataMappings><DxContextMenuDataMapping Text="@nameof(ContextMenuItem.Text)" Visible="@nameof(ContextMenuItem.Visible)" Enabled="@nameof(ContextMenuItem.Enabled)" BeginGroup="@nameof(ContextMenuItem.BeginGroup)" CssClass="@nameof(ContextMenuItem.CssClass)" IconCssClass="@nameof(ContextMenuItem.IconCssClass)" /></DataMappings></DxContextMenu>@code { DxContextMenu RowContextMenu { get; set; } IEnumerable RowContextMenuData { get; set; } int ContextMenuRowIndex { get; set; } [Parameter] public IGrid Grid { get; set; } JobState JobState { get; set; } = new();public async Task Grid_ContextMenu(GridCustomizeElementEventArgs e, MouseEventArgs mouseArgs) { if (GridContextMenuHelper.IsRowContextMenuElement(e.ElementType)) { ContextMenuRowIndex = e.VisibleIndex; RowContextMenuData = GridContextMenuHelper.GetRowItems(e); await RowContextMenu.ShowAsync(mouseArgs); } }}The visibleid in Grid_ContextMenu should be the correct Id in this line
ContextMenuRowIndex = e.VisibleIndex;but it is always the id of the row just above.
GridCustomizeElementEventArgs does not return the correct index.
I did not find anything that helped me go forward. I am thankful for any help