About
August 8, 2026 ยท View on GitHub
About
Blazor component that renders a customizable data Grid (HTML table) from any IEnumerable<TItem> data source.
All components work with WebAssembly and Server hosted models.
For code examples see usage.
You can try it out by using the demo app.
Grid supports two usage "modes":
- Basic: just define columns with
Fieldnames, Grid renders a plain HTML table. - Advanced: enable
AllowSortingandAllowPagingfeatures, use custom Header templates (e.g. with icons), custom cell templates and custom styling.
Components
DataGrid<TItem>: renders customizable data Grid (table) with optional sorting, paging and styling.DataGridColumn<TItem>: defines a column of theDataGridwith data field, header, templates, sorting and styling settings.
DataGrid<TItem> component
Properties
Items:IEnumerable<TItem>?- Required
Data source of the Grid.ChildContent:RenderFragment- Required
HTML content to defineDataGridColumncolumns.EmptyDataTemplate:RenderFragment?
Optional HTML content rendered when the Grid has no data to show.AllowSorting:bool { get; set; }(default: false)
Enables or disables column sorting for the whole Grid.AllowPaging:bool { get; set; }(default: false)
Enables or disables paging of the Grid data.AllowColumnResize:bool { get; set; }(default: false)
Enables or disables column resizing with native CSSresizefor the whole Grid. Drag the handle at the bottom right corner of the column Header.PageSize:int { get; set; }(default: 10)
Number of data rows to show per page whenAllowPagingwas enabled.CurrentPage:int { get; set; }(default: 1)
Gets or sets the current page number (1 based). Supports@bind-CurrentPagetwo-way binding.ShowPagerInfo:bool { get; set; }(default: true)
Determines whether the pager should show page info text or not.PagerButtonCount:int { get; set; }(default: 5)
Number of page buttons to show in the pager.Striped:bool { get; set; }(default: false)
Renders the Grid with striped rows usingStripeColor.Bordered:bool { get; set; }(default: true)
Renders the Grid with borders on all cells usingBorderColor.Hoverable:bool { get; set; }(default: true)
Enables row highlighting withHoverColorwhen mouse pointer is over a data row.HeaderBackgroundColor:string { get; set; }(default: "WhiteSmoke")
Sets thebackground-colorof the Grid Header. Use HTML specified: Color Names, RGB, HEX or with HSL values.HeaderTextColor:string { get; set; }(default: "Black")
Sets the textcolorof the Grid Header.StripeColor:string { get; set; }(default: "WhiteSmoke")
Sets thebackground-colorof even data rows whenStripedwas enabled.HoverColor:string { get; set; }(default: light blue)
Sets thebackground-colorof hovered data row whenHoverablewas enabled.BorderColor:string { get; set; }(default: "LightGray")
Sets theborder-colorof the Grid whenBorderedwas enabled.TableCssClass:string? { get; set; }
Custom CSS class(es) applied to the renderedtableHTML element e.g. Bootstrap: "table table-sm".Columns:IEnumerable<DataGridColumn<TItem>> { get; }
Returns all the column references added to the Grid.SortedColumn:DataGridColumn<TItem>? { get; }
Returns the currently sorted column or NULL.SortDirection:SortDirections { get; }
Returns the currently applied sort direction.TotalItemCount:int { get; }
Returns the total number of data items in the Grid data source.PageCount:int { get; }
Returns the total number of pages.InnerElementReference:ElementReference { get; }
Exposes a BlazorElementReferenceof the wrapped around HTML element.AllOtherAttributes:Dictionary<string, object>
Blazor capture for any unmatched HTML attributes applied to the wrapperdivelement.
Events
OnRowClicked:EventCallback<TItem>
Callback function called when a data row was clicked. Clicked data item is the callback parameter.OnSortChanged:EventCallback<DataGridSortEventArgs>
Callback function called when Grid sorting was changed.CurrentPageChanged:EventCallback<int>
Callback function called when the current page was changed.
Functions
SortByAsync(DataGridColumn<TItem> column, SortDirections sortDirection):Task
Sorts the Grid by the given column with the given direction.GoToPageAsync(int page):Task
Navigates the Grid to the given page number (1 based).Refresh():void
Re-renders the Grid. Can be used when the data source was changed externally.
DataGridColumn<TItem> component
Properties
Field:string? { get; set; }
Name of the data Field (public property of the data item Type) rendered to the cells. Also used as fallback for Header text and for sorting whenSortKeySelectorwas not provided.Title:string? { get; set; }
Header text of the column. When not setFieldname is used.HeaderTemplate:RenderFragment?
Optional HTML content to render custom Header e.g. with icons. It overridesTitletext.CellTemplate:RenderFragment<TItem>?
Optional HTML content to render custom cell content with the current data item as context.Format:string? { get; set; }
Standard .NET Format string applied to the cell value whenCellTemplatewas not provided e.g. "{0:d}", "{0:C2}", etc.Sortable:bool { get; set; }(default: true)
Determines whether the column can be sorted or not. NOTE: it only works whenAllowSortingwas enabled on the parentDataGrid.SortKeySelector:Func<TItem, object?>?
Optional Func to provide custom sort key for the column.Resizable:bool { get; set; }(default: true)
Determines whether the column can be resized or not. NOTE: it only works whenAllowColumnResizewas enabled on the parentDataGrid.Hidden:bool { get; set; }(default: false)
Determines whether the current rendered column should be hidden or not.Width:string? { get; set; }
Sets the width of the column with CSS value e.g. "100px", "20%", "auto", etc.TextAlign:TextAligns { get; set; }(default: Left)
Determines the text alignment of the rendered cells {Left, Center, Right}.HeaderCssClass,HeaderStyle,CellCssClass,CellStyle:string? { get; set; }
Custom CSS class and style values applied to the column Headerthand data celltdHTML elements.
Configuration
Installation
Majorsoft.Blazor.Components.Grid is available on NuGet.
dotnet add package Majorsoft.Blazor.Components.Grid
Use the --version option to specify a preview version to install.
Usage
Add using statement to your Blazor <component/page>.razor file. Or globally reference it into _Imports.razor file.
@using Majorsoft.Blazor.Components.Grid
Basic Grid:
<DataGrid Items="_employees">
<DataGridColumn TItem="Employee" Field="Name" />
<DataGridColumn TItem="Employee" Field="Position" />
<DataGridColumn TItem="Employee" Field="Salary" Format="{0:C0}" TextAlign="TextAligns.Right" />
</DataGrid>
Advanced Grid with sorting, paging, header icons, custom cell template and styling:
<DataGrid Items="_employees"
AllowSorting="true"
AllowPaging="true"
PageSize="5"
Striped="true"
HeaderBackgroundColor="navy"
HeaderTextColor="white"
OnRowClicked="e => _selected = e">
<DataGridColumn TItem="Employee" Field="Name">
<HeaderTemplate><i class="fa fa-user"></i> Name</HeaderTemplate>
</DataGridColumn>
<DataGridColumn TItem="Employee" Field="BirthDate" Title="Birth date" Format="{0:d}" />
<DataGridColumn TItem="Employee" Title="Actions" Sortable="false">
<CellTemplate Context="employee">
<button class="btn btn-sm btn-primary" @onclick="() => Edit(employee)">Edit</button>
</CellTemplate>
</DataGridColumn>
</DataGrid>