Dear Support-Team,
I am using a Grid with a context menu. The context menu has a an item which opens a modal dialog. I need to await the result of the dialog before proceeding as it requires input from the user.
I encountered the following issue:
The context menu stays open until the first click in the modal dialog.
How can I close the context menu manually before opening the modal dialog?
I created the following sample code to demonstrate the issue.
<div class="container-fluid">
<SfGrid DataSource="@Orders" Height="600px" ContextMenuItems="@(new List<ContextMenuItemModel>() { new ContextMenuItemModel { Text = "Open Dialog", Target = ".e-content", Id = "open" } })">
<GridEvents ContextMenuItemClicked="OnContextMenuClick" TValue="Order"></GridEvents>
<GridColumns>
<GridColumn Field=@nameof(Order.OrderID) HeaderText="Order ID" TextAlign="TextAlign.Right" Width="120"></GridColumn>
<GridColumn Field=@nameof(Order.CustomerID) HeaderText="Customer Name" Width="150"></GridColumn>
<GridColumn Field=@nameof(Order.OrderDate) HeaderText=" Order Date" Format="d" Type="ColumnType.Date" TextAlign="TextAlign.Right" Width="130"></GridColumn>
<GridColumn Field=@nameof(Order.Freight) HeaderText="Freight" Format="C2" TextAlign="TextAlign.Right" Width="120"></GridColumn>
</GridColumns>
</SfGrid>
</div>
<SfDialog Width="250px" IsModal="true" @bind-Visible="@Visibility">
<DialogEvents OnOverlayClick="@OnOverlayclick">
</DialogEvents>
<DialogTemplates>
<Content> This is a modal dialog </Content>
</DialogTemplates>
</SfDialog>
@code{
public List<Order> Orders { get; set; }
private bool Visibility { get; set; } = false;
public Order SelectedOrder;
protected override void OnInitialized()
{
Orders = Enumerable.Range(1, 75).Select(x => new Order()
{
OrderID = 1000 + x,
CustomerID = (new string[] { "ALFKI", "ANANTR", "ANTON", "BLONP", "BOLID" })[new Random().Next(5)],
Freight = 2.1 * x,
OrderDate = DateTime.Now.AddDays(-x),
}).ToList();
}
public class Order
{
public int? OrderID { get; set; }
public string CustomerID { get; set; }
public DateTime? OrderDate { get; set; }
public double? Freight { get; set; }
}
public async Task OnContextMenuClick(ContextMenuClickEventArgs<Order> args)
{
Console.WriteLine(args.Item.Id);
if (args.Item.Id == "open")
{
// Close Context Menu here
this.Visibility = true;
await Task.Delay(3000);
}
}
private void OnOverlayclick(MouseEventArgs arg)
{
this.Visibility = false;
}
}
|
public async Task OnContextMenuClick(ContextMenuClickEventArgs<Order> args)
{
Console.WriteLine(args.Item.Id);
if (args.Item.Id == "open")
{
this.Visibility = true;
//await Task.Delay(3000);
}
}
|
Hey Vignesh,
thanks for your answer!
The time delay is there for a reason. In my application, I am using a modal which asks the user for input. In order to process the user input, I need to wait for the submission of the modal.
I added the time delay, because I did not want to implemented my whole modal in the sample code. Instead of the delay, I use "await for the model" in my appl