diff --git a/RadzenBlazorDemos/Pages/DataGridColumnPicking.razor b/RadzenBlazorDemos/Pages/DataGridColumnPicking.razor index 5916cf79dd7..b6266571662 100644 --- a/RadzenBlazorDemos/Pages/DataGridColumnPicking.razor +++ b/RadzenBlazorDemos/Pages/DataGridColumnPicking.razor @@ -4,38 +4,50 @@ @inherits DbContextPage - EmployeeIDVisible = !EmployeeIDVisible) class="rz-my-4"/> - - - - - - - - - - - - - - - - - - - - - - +@inject ContextMenuService ContextMenuService + + +
Column picker type:
+ +
+
+ + { if(columnPickerType == ColumnPickerType.ContextMenu) ShowColumnPicker(args); })> + EmployeeIDVisible = !EmployeeIDVisible) class="rz-my-4" style="width:fit-content"/> + + + + + + + + + + + + + + + + + + + + + + + @code { bool EmployeeIDVisible = false; IEnumerable employees; EventConsole console; + RadzenDataGrid grid; protected override async Task OnInitializedAsync() { @@ -49,4 +61,29 @@ EmployeeIDVisible = args.Columns.Select(c => c.Property).Contains(nameof(Employee.EmployeeID)); console.Log($"Picked columns: {string.Join(", ", args.Columns.Select(c => c.Title))}"); } + + void ShowColumnPicker(MouseEventArgs args) => ContextMenuService.Open(args, ds => + @ { + var checkedColumns = ((IEnumerable)args).Cast>(); + grid.ColumnsCollection.ToList().ForEach(c => c.Visible = checkedColumns.Contains(c)); + EmployeeIDVisible = checkedColumns.Select(c => c.Property).Contains(nameof(Employee.EmployeeID)); + }) + /> + ); + + ColumnPickerType columnPickerType; + public enum ColumnPickerType + { + Default, + ContextMenu + } } \ No newline at end of file diff --git a/RadzenBlazorDemos/Pages/DataGridColumnPickingPage.razor b/RadzenBlazorDemos/Pages/DataGridColumnPickingPage.razor index e77370d033e..1d2aa674d2b 100644 --- a/RadzenBlazorDemos/Pages/DataGridColumnPickingPage.razor +++ b/RadzenBlazorDemos/Pages/DataGridColumnPickingPage.razor @@ -4,7 +4,7 @@ DataGrid Column Picker - Enable column picker by setting the AllowColumnPicking property to true. + Enable default column picker by setting the AllowColumnPicking property to true or use the code example for context menu to create your own custom column picker.