1 - 10 of 25 items
25 items
Enable Column Chooser to allow users to show or hide columns in the DataGrid.
Enable the feature by setting ColumnChooser to true.
ColumnDisplayingChanged event to perform custom actions when a column's display state changes.
<DataGrid TItem="Employee" Data="inMemoryData" Responsive ShowColumnChooser PagerPosition="DataGridPagerPosition.Top" ShowPager ShowPageSizes ColumnDisplayingChanged=""> </DataGrid>
@code { [Inject] EmployeeData EmployeeData { get; set; } private IEnumerable<Employee> inMemoryData; protected override async Task OnInitializedAsync() { inMemoryData = ( await EmployeeData.GetDataAsync().ConfigureAwait( false ) ).Take( 25 ); await base.OnInitializedAsync(); } protected void ColumnDisplayChanged( ColumnDisplayChangedEventArgs<Employee> args ) { Console.WriteLine( $"Column: {args.Column.Field} | Display: {args.Display}" ); } }
Displaying property to false. This will hide the column by default, but it will still be available in the column chooser for users to show if they wish.
<DataGrid TItem="Employee" Data="Data" ShowColumnChooser> <DataGridColumns> <DataGridColumn TItem="Employee" Field="@nameof( Employee.Name )" Caption="Name" /> <DataGridColumn TItem="Employee" Field="@nameof( Employee.Salary )" Caption="Salary" Displaying="false" /> </DataGridColumns> </DataGrid>
@code { public IEnumerable<Employee> Data { get; set; } = new List<Employee>() { new() { Name = "John", Salary = 1000m }, new() { Name = "Sarah", Salary = 2000m }, }; public class Employee { public string Name { get; set; } public decimal Salary { get; set; } } }
ColumnChooserPosition property.
<DataGrid TItem="Employee" Data="inMemoryData" Responsive ShowColumnChooser PagerPosition="DataGridPagerPosition.Top" PagerOptions="new DataGridPagerOptions() { ColumnChooserPosition = PagerElementPosition.End }"> </DataGrid>
@code { [Inject] EmployeeData EmployeeData { get; set; } private IEnumerable<Employee> inMemoryData; protected override async Task OnInitializedAsync() { inMemoryData = ( await EmployeeData.GetDataAsync().ConfigureAwait( false ) ).Take( 25 ); await base.OnInitializedAsync(); } }
See the documentation below for a complete reference to all of the props and classes available to the components mentioned here.