Blazorise DataGrid: Columns
DataGrid provides many types of columns. You can use built-in columns such as text, numeric, date, checkbox, select, etc to automatically create specialized content.
Default Column
Default column template for text values. In this example, we are using the default column template for theEmployee.Email
property.
<DataGrid TItem="Employee" Data="" PageSize="5" Responsive Editable Filterable> <DataGridColumn Field="@nameof(Employee.Email)" Caption="Email" Editable /> <DataGridCommandColumn /> </DataGrid>
@code { [Inject] public EmployeeData EmployeeData { get; set; } private List<Employee> employeeList; protected override async Task OnInitializedAsync() { employeeList = await EmployeeData.GetDataAsync(); await base.OnInitializedAsync(); } }
Check Column
Column template for boolean values<DataGrid TItem="Employee" Data="" PageSize="5" Responsive Editable Filterable> <DataGridCheckColumn Field="@nameof(Employee.IsActive)" Caption="Active" Editable /> <DataGridCommandColumn /> </DataGrid>
@code { [Inject] public EmployeeData EmployeeData { get; set; } private List<Employee> employeeList; protected override async Task OnInitializedAsync() { employeeList = await EmployeeData.GetDataAsync(); await base.OnInitializedAsync(); } }
Date Column
Column template for datetime values<DataGrid TItem="Employee" Data="" PageSize="5" Responsive Editable Filterable> <DataGridDateColumn Field="@nameof(Employee.DateOfBirth)" Caption="Date Of Birth" Editable /> <DataGridCommandColumn /> </DataGrid>
@code { [Inject] public EmployeeData EmployeeData { get; set; } private List<Employee> employeeList; protected override async Task OnInitializedAsync() { employeeList = await EmployeeData.GetDataAsync(); await base.OnInitializedAsync(); } }
Date Column with Native Mode
Column template for datetime values. Set NativeInputMode if you prefer to use the native html input variant of the date input.<DataGrid TItem="Employee" Data="" PageSize="5" Responsive Editable Filterable> <DataGridDateColumn Field="@nameof(Employee.DateOfBirth)" Caption="Date Of Birth" Editable NativeInputMode /> <DataGridCommandColumn /> </DataGrid>
@code { [Inject] public EmployeeData EmployeeData { get; set; } private List<Employee> employeeList; protected override async Task OnInitializedAsync() { employeeList = await EmployeeData.GetDataAsync(); await base.OnInitializedAsync(); } }
Numeric Column
Column template for numeric values<DataGrid TItem="Employee" Data="" PageSize="5" Responsive Editable Filterable> <DataGridNumericColumn Field="@nameof(Employee.Salary)" Caption="Salary" Editable /> <DataGridCommandColumn /> </DataGrid>
@code { [Inject] public EmployeeData EmployeeData { get; set; } private List<Employee> employeeList; protected override async Task OnInitializedAsync() { employeeList = await EmployeeData.GetDataAsync(); await base.OnInitializedAsync(); } }
Numeric Column with Native Mode
Column template for numeric values. Set NativeInputMode if you prefer to use the native html input variant of the numeric input.<DataGrid TItem="Employee" Data="" PageSize="5" Responsive Editable Filterable> <DataGridNumericColumn Field="@nameof(Employee.Salary)" Caption="Salary" Editable NativeInputMode /> <DataGridCommandColumn /> </DataGrid>
@code { [Inject] public EmployeeData EmployeeData { get; set; } private List<Employee> employeeList; protected override async Task OnInitializedAsync() { employeeList = await EmployeeData.GetDataAsync(); await base.OnInitializedAsync(); } }
Select Column
Column template for selectable values<DataGrid TItem="Employee" Data="" PageSize="5" Responsive Editable Filterable> <DataGridSelectColumn TItem="Employee" Field="@nameof( Employee.Gender )" Caption="Gender" Editable Data="EmployeeData.Genders" ValueField="(x) => ((Gender)x).Code" TextField="(x) => ((Gender)x).Description" /> <DataGridCommandColumn /> </DataGrid>
@code { [Inject] public EmployeeData EmployeeData { get; set; } private List<Employee> employeeList; protected override async Task OnInitializedAsync() { employeeList = await EmployeeData.GetDataAsync(); await base.OnInitializedAsync(); } }
API
See the documentation below for a complete reference to all of the props and classes available to the components mentioned here.