[!Note] Please note that this control has been deprecated and replaced with the Grid, and as such, we recommend migrating to that control. This will not be receiving any new features, bug fixes will be deprioritized. For help or questions on migrating your codebase to the Data Grid, please contact support.
Blazor Data Grid Overview
The Ignite UI for Blazor Data Table / Data Grid is a tabular Blazor grid component that allows you to quickly bind and display your data with little coding or configuration. Features of the Blazor data grid include filtering, sorting, templates, row selection, row grouping, row pinning and movable columns. The Blazor tables are optimized for live, streaming data, with the ability to handle unlimited data set size in number of rows or columns.
Blazor Data Grid Example
This demo implements some of the features that are available in the Grid: Filtering, Grouping, Pin/Unpin columns, Reposition columns, Sorting, and Summaries
Getting Started
Dependencies
Please refer to these topics on adding the IgniteUI.Blazor package.
Afterwards, you may start implementing the control by adding the following namespaces:
@using IgniteUI.Blazor.Controls
Component Modules
The IgbGrid
requires the following modules:
// in Program.cs file
builder.Services.AddIgniteUIBlazor(typeof(IgbDataGridModule));
Optional Modules
The optional IgbGrid
features, seen above, requires the following modules:
// in Program.cs file
builder.Services.AddIgniteUIBlazor(
typeof(IgbDataGridModule),
typeof(IgbDataGridToolbarModule),
typeof(IgbSparklineModule)
);
Sample Data Source
Now that the Blazor data grid module is imported, next is the basic configuration of the Blazor grid that binds to local data.
@code {
public List<SaleInfo> DataSource { get; set;}
Random Rand = new Random();
protected override void OnInitialized()
{
GenerateData();
}
public void GenerateData()
{
string[] names = new string[] {
"Intel CPU", "AMD CPU",
"Intel Motherboard", "AMD Motherboard", "Nvidia Motherboard",
"Nvidia GPU", "Gigabyte GPU", "Asus GPU", "AMD GPU", "MSI GPU",
"Corsair Memory", "Patriot Memory", "Skill Memory",
"Samsung HDD", "WD HDD", "Seagate HDD", "Intel HDD", "Asus HDD",
"Samsung SSD", "WD SSD", "Seagate SSD", "Intel SSD", "Asus SSD",
"Samsung Monitor", "Asus Monitor", "LG Monitor", "HP Monitor" };
string[] countries = new string[] {
"USA", "UK", "France", "Canada", "Poland",
"Denmark", "Croatia", "Australia", "Seychelles",
"Sweden", "Germany", "Japan", "Ireland",
"Barbados", "Jamaica", "Cuba", "Spain", };
string[] status = new string[] { "Packing", "Shipped", "Delivered" };
var sales = new List<SaleInfo>();
for (var i = 0; i < 200; i++)
{
var price = GetRandomNumber(10000, 90000) / 100;
var items = GetRandomNumber(4, 30);
var value = Math.Round(price * items);
var margin = GetRandomNumber(2, 5);
var profit = Math.Round((price * margin / 100) * items);
var country = GetRandomItem(countries);
var item = new SaleInfo()
{
Country = country,
CountryFlag = GetCountryFlag(country),
Margin = margin,
OrderDate = GetRandomDate(),
OrderItems = items,
OrderValue = value,
ProductID = 1001 + i,
ProductName = GetRandomItem(names),
ProductPrice = price,
Profit = Math.Round(profit),
Status = GetRandomItem(status)
};
sales.Add(item);
}
this.DataSource = sales;
}
public double GetRandomNumber(double min, double max)
{
return Math.Round(min + (Rand.NextDouble() * (max - min)));
}
public string GetRandomItem(string[] array)
{
var index = (int)Math.Round(GetRandomNumber(0, array.Length - 1));
return array[index];
}
public DateTime GetRandomDate() {
var today = new DateTime();
var year = today.Year;
var month = this.GetRandomNumber(1, 9);
var day = this.GetRandomNumber(10, 27);
return new DateTime(year, (int)month, (int)day);
}
public string GetCountryFlag(string country)
{
var flag = "https://static.infragistics.com/xplatform/images/flags/" + country + ".png";
return flag;
}
public class SaleInfo
{
public string? Status { get; set; }
public string? ProductName { get; set; }
public string? CountryFlag { get; set; }
public string? Country { get; set; }
public DateTime OrderDate { get; set; }
public double Profit { get; set; }
public double ProductPrice { get; set; }
public double ProductID { get; set; }
public double OrderValue { get; set; }
public double OrderItems { get; set; }
public double Margin { get; set; }
}
}
Auto-Generate Columns
The following code demonstrates how to bind the Blazor data grid to the above local data.
<IgbDataGrid Height="100%"
Width="100%"
DataSource="DataSource"
AutoGenerateColumns="true"
DefaultColumnMinWidth="100"
SummaryScope="SummaryScope.Root"
IsColumnOptionsEnabled="true"
IsGroupCollapsable="true"
GroupSummaryDisplayMode="GroupSummaryDisplayMode.RowBottom"
ColumnMovingMode="ColumnMovingMode.Deferred"
ColumnMovingAnimationMode="ColumnMovingAnimationMode.SlideOver"
ColumnMovingSeparatorWidth="2"
ColumnShowingAnimationMode="ColumnShowingAnimationMode.SlideFromRightAndFadeIn"
ColumnHidingAnimationMode="ColumnHidingAnimationMode.SlideToRightAndFadeOut"
SelectionMode="GridSelectionMode.SingleRow"
CornerRadiusTopLeft="0"
CornerRadiusTopRight="0" />
Manually Define Columns
<IgbDataGrid Height="100%"
Width="100%"
DataSource="DataSource"
AutoGenerateColumns="false">
<IgbNumericColumn Field="ProductID" HeaderText="Product ID" />
<IgbTextColumn Field="ProductName" HeaderText="Product Name" />
<IgbTextColumn Field="QuantityPerUnit" HeaderText="Quantity Per Unit" />
<IgbNumericColumn Field="UnitsInStock" HeaderText="Units In Stock" />
<IgbDateTimeColumn Field="OrderDate" HeaderText="Order Date" />
</IgbDataGrid>
Styling Columns
The following code demonstrates how to style specific columns using the provided column's properties.
<IgbTextColumn
Background="SkyBlue"
FontStyle="italic"
FontWeight="bold"
FontFamily="Times New Roman"
FontSize="16"
/>
Tutorial Video
Learn more about creating a Blazor data grid in our short tutorial video:
Additional Resources
- Accessibility Compliance
- Cell Activation
- Grid Editing
- Cell Selection
- Column Animation
- Column Chooser
- Column Filtering
- Column Moving
- Column Options
- Column Resizing
- Column Sorting
- Column Types
- Performance
- Row Pinning
- Row Grouping
- Row Highlighting