Welcome to the Blazor feedback portal. We’re happy you’re here! If you have feedback on how to improve the Blazor, we’d love to hear it!

  • Check out the features or bugs others have reported and vote on your favorites. Feedback will be prioritized based on popularity.
  • If you have feedback that’s not listed yet, submit your own.

Thanks for joining our community and helping improve Syncfusion products!

2
Votes

Hi,

I am trying to implement dynamic cntext menu items that will vary depending upon the selected column.  The particular use case that I'm trying to achieve is to Freeze / Unfreeze columns.

I have attached a sample application and video showing the behavior observed.  The following code snippets show the key components.

With reference to the video, when I try and right click on a column heading, I seem to get an oscilating list of context menu items.  

Can you please let me know if I have implemented something incorrectly, or if there is a bug?


<SfGrid DataSource="@ObservableData" AllowPaging="true"  ContextMenuItems="@_contextMenuItems">   
     <GridEvents TValue="ObservableDatas"  ContextMenuOpen="OnContextMenuOpen" />



   private object? _contextMenuItems = new List() ;

    private void OnContextMenuOpen(ContextMenuOpenEventArgs args)

    {

        var args1 = args;

        var items = new List();

        items.Add("AutoFit");


        if (args.Column.HeaderText == "Customer ID")

        {

            items.Add("AutoFitAll");

        }


        items.Add("SortAscending");

        items.Add("SortDescending");

        items.Add("PdfExport");

        items.Add("ExcelExport");

        items.Add("FirstPage");

        items.Add("PrevPage");

        items.Add("NextPage");

        items.Add("LastPage");


        if (args.Column.IsFrozen)

        {

            items.Add(new ContextMenuItemModel() {Id = "UnfreezeCol", Text = "Unfreeze Column", Target = "e-header"});

        }

        else

        {

            items.Add(new ContextMenuItemModel() {Id = "FreezeColLeft", Text = "Freeze Column Left", Target = "e-header"});

            items.Add(new ContextMenuItemModel() {Id = "FreezeColRight", Text = "Freeze Column Right", Target = "e-header"});

        }


        _contextMenuItems = items;

    }