You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: blazor/datagrid/context-menu.md
+35-38Lines changed: 35 additions & 38 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -9,14 +9,14 @@ documentation: ug
9
9
10
10
# Context menu in Syncfusion Blazor DataGrid
11
11
12
-
The Syncfusion<supstyle="font-size:70%">®</sup> Blazor DataGrid supports a context menu that appears when right-clicking any part of the Grid. This menu provides quick access to actions and operations related to the Grid’s data.
12
+
The Syncfusion<supstyle="font-size:70%">®</sup> Blazor DataGrid supports a context menu that appears when right-clicking anywhere within the grid. This menu provides quick access to actions related to the grid’s data and layout, enhancing interactivity and usability.
13
13
14
14
To enable the context menu, configure the Grid's [ContextMenuItems](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Grids.ContextMenuItemModel.html) property. Use default items for built-in menu options or add custom items for tailored functionality. This feature improves interactivity by offering context-sensitive actions.
15
15
16
16
The context menu appears when right-clicking in these Grid areas:
17
-
***Header:**Right-click the header for column-specific actions.
18
-
***Content:**Right-click the main content for row-specific actions.
19
-
***Pager:**Right-click the pager for navigation options.
17
+
***Header:**Displays column-specific actions.
18
+
***Content:**Shows row-related options.
19
+
***Pager:**Offers navigation controls.
20
20
21
21
The default context menu items include:
22
22
@@ -53,7 +53,6 @@ The default context menu items include:
53
53
|`LastPage`| Navigate to the last page of the Grid. |
54
54
|`NextPage`| Navigate to the next page of the Grid. |
55
55
56
-
**Example: Enable the context menu feature in the Grid**
57
56
58
57
{% tabs %}
59
58
{% highlight razor tabtitle="Index.razor" %}
@@ -149,8 +148,6 @@ To configure custom context menu items:
149
148
2. Specify properties such as **Text**, **Target**, and **Id** for each custom item.
150
149
3. Handle actions using the [ContextMenuItemClicked](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Grids.ContextMenuClickEventArgs-1.html) event.
151
150
152
-
**Example: Add a custom context menu item to copy data with headers**
153
-
154
151
The [CopyAsync](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Grids.SfGrid-1.html#Syncfusion_Blazor_Grids_SfGrid_1_CopyAsync_System_Nullable_System_Boolean__) method is used to copy selected rows or cells, including headers, to the clipboard.
155
152
156
153
{% tabs %}
@@ -249,8 +246,6 @@ To configure **built-in** and **custom** context menu items:
249
246
2. For custom items, specify properties such as **Text**, **Target**, and **Id**.
250
247
3. Handle custom actions using the [ContextMenuItemClicked](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Grids.ContextMenuClickEventArgs-1.html) event.
251
248
252
-
**Example: Combine built-in and custom context menu items**
253
-
254
249
The [CopyAsync](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Grids.SfGrid-1.html#Syncfusion_Blazor_Grids_SfGrid_1_CopyAsync_System_Nullable_System_Boolean__) method copies selected rows or cells, including headers, to the clipboard.
255
250
256
251
{% tabs %}
@@ -342,16 +337,14 @@ public class OrderData
342
337
343
338
## Sub context menu items in DataGrid
344
339
345
-
The Syncfusion<supstyle="font-size:70%">®</sup> Blazor DataGrid supports hierarchical context menu structures, allowing sub-context menu items to appear as child options under a parent item. This feature helps organize multiple related actions under a single top-level context menu item.
340
+
The Syncfusion<supstyle="font-size:70%">®</sup> Blazor DataGrid supports hierarchical context menus, allowing sub-items to be grouped under a parent menu item. This structure helps organize related actions and improves interface usability.
346
341
347
342
To configure sub-context menu items:
348
343
349
344
1. Define the [ContextMenuItems](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Grids.ContextMenuItemModel.html) property with a list of [ContextMenuItemModel](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Grids.ContextMenuItemModel.html) objects.
350
-
2. Add sub-items by specifying the collection for the Items property in ContextMenuItemModel.
345
+
2. Add sub-items by specifying the collection for the Items property in `ContextMenuItemModel`.
351
346
3. Handle actions using the [ContextMenuItemClicked](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Grids.ContextMenuClickEventArgs-1.html) event.
352
347
353
-
**Example: Sub Context Menu Items**
354
-
355
348
This example creates a sub-context menu titled **Clipboard**, which includes the sub-items **Copy** and **Copy With Header**. When the `ContextMenuItemClicked` event is triggered, the [CopyAsync](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Grids.SfGrid-1.html#Syncfusion_Blazor_Grids_SfGrid_1_CopyAsync_System_Nullable_System_Boolean__) method runs to copy data with or without headers.
356
349
357
350
{% tabs %}
@@ -461,19 +454,19 @@ public class OrderData
461
454
462
455
## Disable the context menu for specific columns in DataGrid
463
456
464
-
The Syncfusion<supstyle="font-size:70%">®</sup> Blazor DataGrid allows restricting the context menu on specific columns—particularly when those columns contain `sensitive` or `read-only` data.
457
+
The Syncfusion<supstyle="font-size:70%">®</sup> Blazor DataGrid allows restricting the context menu for individual columns, which is useful when dealing with **sensitive** or **read-only** data.
465
458
466
-
This behavior can be controlled using the [ContextMenuOpen](https://blazor.syncfusion.com/documentation/datagrid/events#contextmenuopen) event. This event is triggered before the context menu is displayed and provides access to the column details. By checking the column field, the menu can be conditionally cancelled.
459
+
This behavior is controlled using the [ContextMenuOpen](https://blazor.syncfusion.com/documentation/datagrid/events#contextmenuopen) event. The event is triggered before the context menu appears and provides access to column details. By checking the column's **Field** property, the context menu can be conditionally disabled.
467
460
468
461
To disable the context menu for a specific column:
469
462
470
463
1. Handle the [ContextMenuOpen](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Grids.GridEvents-1.html#Syncfusion_Blazor_Grids_GridEvents_1_ContextMenuOpen) event of the Grid.
471
-
2. Use the **Column.Field** property to identify the column.
472
-
3. Set **args.Cancel** to `true` to prevent the menu from opening for that column.
473
-
474
-
**Example: Disable Context Menu for Specific Columns**
464
+
2. Use the **args.Column.Field** property to identify the target column.
465
+
3. Set **args.Cancel = true** to prevent the context menu from opening for that column.
475
466
476
-
The [ContextMenuItemClicked](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Grids.ContextMenuClickEventArgs-1.html) event handles actions triggered by context menu item clicks. The [CopyAsync](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Grids.SfGrid-1.html#Syncfusion_Blazor_Grids_SfGrid_1_CopyAsync_System_Nullable_System_Boolean__) method executes for all columns except **Freight**, where the context menu is disabled.
467
+
In this example:
468
+
- The context menu is disabled for the **Freight** column.
469
+
- The [CopyAsync](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Grids.SfGrid-1.html#Syncfusion_Blazor_Grids_SfGrid_1_CopyAsync_System_Nullable_System_Boolean__) method executes for all other columns when the **Copy with headers** option is selected.
477
470
478
471
{% tabs %}
479
472
{% highlight razor tabtitle="Index.razor" %}
@@ -572,15 +565,13 @@ public class OrderData
572
565
573
566
## Enable or disable context menu items
574
567
575
-
The Syncfusion<supstyle="font-size:70%">®</sup> Blazor DataGrid allows dynamically enabling or disabling specific context menu items using the [Disabled](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Navigations.MenuItem.html#Syncfusion_Blazor_Navigations_MenuItem_Disabled) property. This feature is useful when certain actions, such as **Edit** or **Delete** should be restricted based on the column, row data, or custom logic.
568
+
The Syncfusion<supstyle="font-size:70%">®</sup> Blazor DataGrid allows dynamic control over the availability of context menu items using the [Disabled](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Navigations.MenuItem.html#Syncfusion_Blazor_Navigations_MenuItem_Disabled) property. This feature is useful for conditionally restricting actions such as **Edit** or **Delete**, based on the column, row data, or custom logic.
576
569
577
570
To achieve this, handle the [ContextMenuOpen](https://blazor.syncfusion.com/documentation/datagrid/events#contextmenuopen) event. The event is triggered before the context menu is displayed and allows enabling or disabling menu items dynamically based on conditions.
578
571
579
572
1. Handle the [ContextMenuOpen](https://blazor.syncfusion.com/documentation/datagrid/events#contextmenuopen) event of the grid.
580
-
2. Use the **Args.ContextMenuObj.Items** collection to access the menu items.
581
-
3. Set the **Disabled** property of the required item(s) to `true` or `false` based on the defined logic.
582
-
583
-
**Example: Enable or Disable Context Menu Items Dynamically**
573
+
2. Use the **args.ContextMenu.Items** collection to access the menu items.
574
+
3. Set the **Disabled** property of the required item(s) to **true** or **false** based on the defined logic.
584
575
585
576
The **Copy** menu item is disabled for the **ShipCity** column and remains enabled for all other columns.
586
577
@@ -611,7 +602,13 @@ The **Copy** menu item is disabled for the **ShipCity** column and remains enabl

670
667
671
668
## Show or hide context menu
672
669
673
-
The Syncfusion<supstyle="font-size:70%">®</sup> Blazor DataGrid allows dynamically showing or hiding specific context menu items using the [Hidden](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Navigations.MenuItem.html#Syncfusion_Blazor_Navigations_MenuItem_Hidden) property. This feature is useful when certain actions, such as Edit or Delete, should be hidden based on the column, row data, or custom logic.
670
+
The Syncfusion<supstyle="font-size:70%">®</sup> Blazor DataGrid allows dynamically showing or hiding specific context menu items using the [Hidden](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Navigations.MenuItem.html#Syncfusion_Blazor_Navigations_MenuItem_Hidden) property. This feature is useful for conditionally restricting actions such as **Edit** or **Delete**, based on the column, row data, or custom logic.
674
671
675
-
To achieve this, handle the [ContextMenuOpen](https://blazor.syncfusion.com/documentation/datagrid/events#contextmenuopen) event. The event is triggered before the context menu is displayed and allows modifying the visibility of menu items dynamically based on conditions.
672
+
To achieve this, handle the [ContextMenuOpen](https://blazor.syncfusion.com/documentation/datagrid/events#contextmenuopen) event. The event is triggered before the context menu is displayed and allows dynamic modification of menu item visibility based on defined conditions.
676
673
677
674
To control the visibility of context menu items:
678
675
679
676
1. Handle the [ContextMenuOpen](https://blazor.syncfusion.com/documentation/datagrid/events#contextmenuopen) event of the grid.
680
-
2. Use the **Args.ContextMenuObj.Items** collection to access the menu items.
681
-
3. Set the [Hidden](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Navigations.MenuItem.html#Syncfusion_Blazor_Navigations_MenuItem_Hidden) property of the required item(s) to `true` or `false` based on the defined logic.
682
-
683
-
**Example: Show or Hide Context Menu Items Dynamically**
677
+
2. Use the **args.ContextMenu.Items** collection to access the menu items.
678
+
3. Set the [Hidden](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Navigations.MenuItem.html#Syncfusion_Blazor_Navigations_MenuItem_Hidden) property of the required item(s) to **true** or **false** based on the defined logic.
684
679
685
680
The **Edit** menu item is hidden for the **CustomerID** column and remains visible for all other columns.
686
681
@@ -711,7 +706,13 @@ The **Edit** menu item is hidden for the **CustomerID** column and remains visib
@@ -780,10 +781,6 @@ To access row data on context menu click:
780
781
2. Handle the [ContextMenuItemClicked](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Grids.ContextMenuClickEventArgs-1.html) event of the grid.
781
782
3. Use the **RowInfo.RowData** property from the event arguments to access the full details of the selected row.
782
783
783
-
**Example: Fetch Row Details on Context Menu Click**
784
-
785
-
The **Fetch Data** menu item retrieves the details of the selected row and displays them below the grid.
0 commit comments