Blazor Tree Grid Summaries
The Ignite UI for Blazor Summaries feature in Blazor Tree Grid functions on a per-column level as group footer. Blazor TreeGrid summaries is powerful feature which enables the user to see column information in a separate container with a predefined set of default summary items, depending on the type of data within the column or by implementing a custom template in the IgbTreeGrid
.
Blazor Tree Grid Summaries Overview Example
using System;
using System.Net.Http;
using System.Collections.Generic;
using System.Threading.Tasks;
using System.Text;
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using IgniteUI.Blazor.Controls; // for registering Ignite UI modules
namespace Infragistics.Samples
{
public class Program
{
public static async Task Main(string[] args)
{
var builder = WebAssemblyHostBuilder.CreateDefault(args);
builder.RootComponents.Add<App>("app");
builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) });
// registering Ignite UI modules
builder.Services.AddIgniteUIBlazor(
typeof(IgbInputModule),
typeof(IgbTreeGridModule)
);
await builder.Build().RunAsync();
}
}
}
csusing System;
using System.Collections.Generic;
public class OrdersTreeDataItem
{
public double ID { get; set; }
public double ParentID { get; set; }
public string Name { get; set; }
public string Category { get; set; }
public string OrderDate { get; set; }
public double Units { get; set; }
public double UnitPrice { get; set; }
public double Price { get; set; }
public bool Delivered { get; set; }
}
public class OrdersTreeData
: List<OrdersTreeDataItem>
{
public OrdersTreeData()
{
this.Add(new OrdersTreeDataItem()
{
ID = 1,
ParentID = -1,
Name = @"Order 1",
Category = @"",
OrderDate = @"2010-02-17",
Units = 1844,
UnitPrice = 3.73,
Price = 6884.38,
Delivered = true
});
this.Add(new OrdersTreeDataItem()
{
ID = 101,
ParentID = 1,
Name = @"Chocolate Chip Cookies",
Category = @"Cookies",
OrderDate = @"2010-02-17",
Units = 834,
UnitPrice = 3.59,
Price = 2994.06,
Delivered = true
});
this.Add(new OrdersTreeDataItem()
{
ID = 102,
ParentID = 1,
Name = @"Red Apples",
Category = @"Fruit",
OrderDate = @"2010-02-17",
Units = 371,
UnitPrice = 3.66,
Price = 1357.86,
Delivered = true
});
this.Add(new OrdersTreeDataItem()
{
ID = 103,
ParentID = 1,
Name = @"Butter",
Category = @"Diary",
OrderDate = @"2010-02-17",
Units = 260,
UnitPrice = 3.45,
Price = 897,
Delivered = true
});
this.Add(new OrdersTreeDataItem()
{
ID = 104,
ParentID = 1,
Name = @"Potato Chips",
Category = @"Snack",
OrderDate = @"2010-02-17",
Units = 118,
UnitPrice = 1.96,
Price = 231.28,
Delivered = true
});
this.Add(new OrdersTreeDataItem()
{
ID = 105,
ParentID = 1,
Name = @"Orange Juice",
Category = @"Beverages",
OrderDate = @"2010-02-17",
Units = 261,
UnitPrice = 5.38,
Price = 1404.18,
Delivered = true
});
this.Add(new OrdersTreeDataItem()
{
ID = 2,
ParentID = -1,
Name = @"Order 2",
Category = @"",
OrderDate = @"2022-05-27",
Units = 1831,
UnitPrice = 8.23,
Price = 15062.77,
Delivered = false
});
this.Add(new OrdersTreeDataItem()
{
ID = 201,
ParentID = 2,
Name = @"Frozen Shrimps",
Category = @"Seafood",
OrderDate = @"2022-05-27",
Units = 120,
UnitPrice = 20.45,
Price = 2454,
Delivered = false
});
this.Add(new OrdersTreeDataItem()
{
ID = 202,
ParentID = 2,
Name = @"Ice Tea",
Category = @"Beverages",
OrderDate = @"2022-05-27",
Units = 840,
UnitPrice = 7,
Price = 5880,
Delivered = false
});
this.Add(new OrdersTreeDataItem()
{
ID = 203,
ParentID = 2,
Name = @"Fresh Cheese",
Category = @"Diary",
OrderDate = @"2022-05-27",
Units = 267,
UnitPrice = 16.55,
Price = 4418.85,
Delivered = false
});
this.Add(new OrdersTreeDataItem()
{
ID = 204,
ParentID = 2,
Name = @"Carrots",
Category = @"Vegetables",
OrderDate = @"2022-05-27",
Units = 360,
UnitPrice = 2.77,
Price = 997.2,
Delivered = false
});
this.Add(new OrdersTreeDataItem()
{
ID = 205,
ParentID = 2,
Name = @"Apple Juice",
Category = @"Beverages",
OrderDate = @"2022-05-27",
Units = 244,
UnitPrice = 5.38,
Price = 1312.72,
Delivered = false
});
this.Add(new OrdersTreeDataItem()
{
ID = 3,
ParentID = -1,
Name = @"Order 3",
Category = @"",
OrderDate = @"2022-08-04",
Units = 1972,
UnitPrice = 3.47,
Price = 6849.18,
Delivered = true
});
this.Add(new OrdersTreeDataItem()
{
ID = 301,
ParentID = 3,
Name = @"Skimmed Milk 1L",
Category = @"Diary",
OrderDate = @"2022-08-04",
Units = 1028,
UnitPrice = 3.56,
Price = 3659.68,
Delivered = true
});
this.Add(new OrdersTreeDataItem()
{
ID = 302,
ParentID = 3,
Name = @"Bananas 5 Pack",
Category = @"Fruit",
OrderDate = @"2022-08-04",
Units = 370,
UnitPrice = 6.36,
Price = 2353.2,
Delivered = true
});
this.Add(new OrdersTreeDataItem()
{
ID = 303,
ParentID = 3,
Name = @"Cauliflower",
Category = @"Vegetables",
OrderDate = @"2022-08-04",
Units = 283,
UnitPrice = 0.95,
Price = 268.85,
Delivered = true
});
this.Add(new OrdersTreeDataItem()
{
ID = 304,
ParentID = 3,
Name = @"White Chocolate Cookies",
Category = @"Cookies",
OrderDate = @"2022-08-04",
Units = 291,
UnitPrice = 1.95,
Price = 567.45,
Delivered = true
});
this.Add(new OrdersTreeDataItem()
{
ID = 4,
ParentID = -1,
Name = @"Order 4",
Category = @"",
OrderDate = @"2023-01-04",
Units = 1065,
UnitPrice = 5.56,
Price = 5923.5,
Delivered = true
});
this.Add(new OrdersTreeDataItem()
{
ID = 401,
ParentID = 4,
Name = @"Mini Milk Chocolate Cookie Bites",
Category = @"Cookies",
OrderDate = @"2023-01-04",
Units = 68,
UnitPrice = 2.25,
Price = 153,
Delivered = true
});
this.Add(new OrdersTreeDataItem()
{
ID = 402,
ParentID = 4,
Name = @"Wild Salmon Fillets",
Category = @"Seafood",
OrderDate = @"2023-01-04",
Units = 320,
UnitPrice = 16.15,
Price = 5168,
Delivered = true
});
this.Add(new OrdersTreeDataItem()
{
ID = 403,
ParentID = 4,
Name = @"Diet Lemonade",
Category = @"Beverages",
OrderDate = @"2023-01-04",
Units = 437,
UnitPrice = 0.5,
Price = 218.5,
Delivered = true
});
this.Add(new OrdersTreeDataItem()
{
ID = 404,
ParentID = 4,
Name = @"Potatoes",
Category = @"Vegetables",
OrderDate = @"2023-01-04",
Units = 240,
UnitPrice = 1.6,
Price = 384,
Delivered = true
});
}
}
cs
@using IgniteUI.Blazor.Controls
@inject IJSRuntime JS
<div class="container vertical ig-typography">
<div class="container vertical fill">
<IgbTreeGrid
AutoGenerate="false"
Data="OrdersTreeData"
Name="treeGrid"
@ref="treeGrid"
Id="treeGrid"
PrimaryKey="ID"
ForeignKey="ParentID">
<IgbColumn
Field="ID"
Header="Order ID">
</IgbColumn>
<IgbColumn
Field="Name"
Header="Order Product"
HasSummary="true"
HeaderTemplateScript="WebTreeGridSummariesHeaderTemplate"
Name="column1"
@ref="column1">
</IgbColumn>
<IgbColumn
Field="Units"
Header="Units"
DataType="GridColumnDataType.Number"
HasSummary="true"
Editable="true"
HeaderTemplateScript="WebTreeGridSummariesHeaderTemplate"
Name="column2"
@ref="column2">
</IgbColumn>
<IgbColumn
Field="UnitPrice"
Header="Unit Price"
DataType="GridColumnDataType.Number"
HasSummary="true"
Editable="true"
HeaderTemplateScript="WebTreeGridSummariesHeaderTemplate"
Name="column3"
@ref="column3">
</IgbColumn>
<IgbColumn
Field="Price"
Header="Price"
DataType="GridColumnDataType.Number"
HasSummary="true"
Editable="true"
HeaderTemplateScript="WebTreeGridSummariesHeaderTemplate"
Name="column4"
@ref="column4">
</IgbColumn>
<IgbColumn
Field="OrderDate"
Header="Order Date"
DataType="GridColumnDataType.Date"
HasSummary="true"
HeaderTemplateScript="WebTreeGridSummariesHeaderTemplate"
Name="column5"
@ref="column5">
</IgbColumn>
<IgbColumn
Field="Delivered"
Header="Delivered"
DataType="GridColumnDataType.Boolean"
HasSummary="true"
HeaderTemplateScript="WebTreeGridSummariesHeaderTemplate"
Name="column6"
@ref="column6">
</IgbColumn>
</IgbTreeGrid>
</div>
</div>
@code {
protected override async Task OnAfterRenderAsync(bool firstRender)
{
var treeGrid = this.treeGrid;
var column1 = this.column1;
var column2 = this.column2;
var column3 = this.column3;
var column4 = this.column4;
var column5 = this.column5;
var column6 = this.column6;
}
private IgbTreeGrid treeGrid;
private IgbColumn column1;
private IgbColumn column2;
private IgbColumn column3;
private IgbColumn column4;
private IgbColumn column5;
private IgbColumn column6;
private OrdersTreeData _ordersTreeData = null;
public OrdersTreeData OrdersTreeData
{
get
{
if (_ordersTreeData == null)
{
_ordersTreeData = new OrdersTreeData();
}
return _ordersTreeData;
}
}
}
razor
igRegisterScript("WebTreeGridSummariesHeaderTemplate", (ctx) => {
var html = window.igTemplating.html;
window.toggleSummary = function toggleSummary(column) {
column.hasSummary = !column.hasSummary;
}
return html`<div>
<span style="float:left">${ctx.column.field}</span>
<span style="float:right; color:${ctx.column.hasSummary ? '#e41c77' : ''}" @pointerdown=${() => toggleSummary(ctx.column)}>∑</span>
</div>`;
}, false);
js/*
CSS styles are loaded from the shared CSS file located at:
https://static.infragistics.com/xplatform/css/samples/
*/
css
The summary of the column is a function of all column values, unless filtering is applied, then the summary of the column will be function of the filtered result values
IgbTreeGrid
summaries can also be enabled on a per-column level in Ignite UI for Blazor, which means that you can activate it only for columns that you need. IgbTreeGrid
summaries gives you a predefined set of default summaries, depending on the type of data in the column, so that you can save some time:
For string
and boolean
DataType
, the following function is available:
- Count
For number
, currency
and percent
data types, the following functions are available:
- Count
- Min
- Max
- Average
- Sum
For date
data type, the following functions are available:
- Count
- Earliest
- Latest
All available column data types could be found in the official Column types topic.
IgbTreeGrid
summaries are enabled per-column by setting HasSummary
property to true. It is also important to keep in mind that the summaries for each column are resolved according to the column data type. In the IgbTreeGrid
the default column data type is string
, so if you want number
or date
specific summaries you should specify the DataType
property as number
or date
. Note that the summary values will be displayed localized, according to the grid Locale
and column PipeArgs
.
<IgbTreeGrid>
<IgbColumn Field="ID" Header="Order ID"></IgbColumn>
<IgbColumn Field="Name" Header="Order Product" HasSummary="true"></IgbColumn>
<IgbColumn Field="Units" Header="Units" HasSummary="true"></IgbColumn>
</IgbTreeGrid>
razor
The other way to enable/disable summaries for a specific column or a list of columns is to use the public method EnableSummaries
/DisableSummaries
of the IgbTreeGrid
.
<IgbTreeGrid AutoGenerate="false" Data="OrdersTreeData" Name="treeGrid" @ref="treeGridRef" Id="treeGrid" PrimaryKey="ID">
<IgbColumn Field="ID" Header="Order ID"></IgbColumn>
<IgbColumn Field="Name" Header="Order Product" HasSummary="true"></IgbColumn>
<IgbColumn Field="Units" Header="Units" DataType="GridColumnDataType.Number" HasSummary="true"></IgbColumn>
</IgbTreeGrid>
@code {
public async void DisableSummaries()
{
object[] disabledSummaries = { "Units" };
await this.treeGrid.DisableSummariesAsync(disabledSummaries);
}
}
razor
Custom Tree Grid Summaries
If these functions do not fulfill your requirements you can provide a custom summary for the specific columns.
//In JavaScript
class PtoSummary {
operate(data, allData, fieldName) {
const result = [];
result.push({
key: 'totalOnPTO',
label: 'Employees On PTO',
summaryResult: this.count(allData.filter((rec) => rec['OnPTO']).map(r => r[fieldName]))
});
result.push({
key: 'devs',
label: 'Developers',
summaryResult: this.count(allData.filter((rec) => rec[fieldName].includes('Developer') && rec['OnPTO']).map(r => r[fieldName]))
});
result.push({
key: 'tl',
label: 'Team Leads',
summaryResult: this.count(allData.filter((rec) => rec[fieldName].includes('Team Lead') && rec['OnPTO']).map(r => r[fieldName]))
});
result.push({
key: 'managers',
label: 'Managers/Directors',
summaryResult: this.count(allData.filter((rec) => (rec[fieldName].includes('Manager') || rec[fieldName].includes('Director')) && rec['OnPTO']).map(r => r[fieldName]))
});
result.push({
key: 'ceo',
label: 'CEO/President',
summaryResult: this.count(allData.filter((rec) => (rec[fieldName].includes('CEO') || rec[fieldName].includes('President')) && rec['OnPTO']).map(r => r[fieldName]))
});
return result;
}
}
razor
As seen in the examples, the base classes expose the Operate
method, so you can choose to get all default summaries and modify the result, or calculate entirely new summary results.
The method returns a list of IgbSummaryResult
.
and take optional parameters for calculating the summaries. See Custom summaries, which access all data section below.
In order to calculate the summary row height properly, the Tree Grid needs the Operate method to always return an array of IgbSummaryResult with the proper length even when the data is empty.
<IgbTreeGrid
AutoGenerate="true"
Name="treeGrid"
@ref="treeGrid"
Data="EmployeesFlatData"
PrimaryKey="ID"
ColumnInitScript="WebTreeGridCustomSummary">
</IgbTreeGrid>
// In Javascript
igRegisterScript("WebTreeGridCustomSummary", (event) => {
if (event.detail.field === "Title") {
event.detail.summaries = PtoSummary;
}
}, false);
razor
Custom summaries, which access all data
Now you can access all Tree Grid data inside the custom column summary. Two additional optional parameters are introduced in the SummaryOperand Operate
method.
As you can see in the code snippet below the operate method has the following three parameters:
- columnData - gives you an array that contains the values only for the current column
- allGridData - gives you the whole grid data source
- fieldName - current column field
class PtoSummary {
operate(data, allData, fieldName) {
const result = [];
result.push({
key: 'totalOnPTO',
label: 'Employees On PTO',
summaryResult: this.count(allData.filter((rec) => rec['OnPTO']).map(r => r[fieldName]))
});
return result;
}
}
razor
using System;
using System.Net.Http;
using System.Collections.Generic;
using System.Threading.Tasks;
using System.Text;
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using IgniteUI.Blazor.Controls; // for registering Ignite UI modules
namespace Infragistics.Samples
{
public class Program
{
public static async Task Main(string[] args)
{
var builder = WebAssemblyHostBuilder.CreateDefault(args);
builder.RootComponents.Add<App>("app");
builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) });
// registering Ignite UI modules
builder.Services.AddIgniteUIBlazor(
typeof(IgbInputModule),
typeof(IgbTreeGridModule)
);
await builder.Build().RunAsync();
}
}
}
csusing System;
using System.Collections.Generic;
public class EmployeesFlatDataItem
{
public double Age { get; set; }
public string HireDate { get; set; }
public double ID { get; set; }
public string Name { get; set; }
public string Phone { get; set; }
public bool OnPTO { get; set; }
public double ParentID { get; set; }
public string Title { get; set; }
}
public class EmployeesFlatData
: List<EmployeesFlatDataItem>
{
public EmployeesFlatData()
{
this.Add(new EmployeesFlatDataItem()
{
Age = 55,
HireDate = @"2008-03-20",
ID = 1,
Name = @"Johnathan Winchester",
Phone = @"0251-031259",
OnPTO = false,
ParentID = -1,
Title = @"Development Manager"
});
this.Add(new EmployeesFlatDataItem()
{
Age = 42,
HireDate = @"2014-01-22",
ID = 4,
Name = @"Ana Sanders",
Phone = @"(21) 555-0091",
OnPTO = true,
ParentID = -1,
Title = @"CEO"
});
this.Add(new EmployeesFlatDataItem()
{
Age = 49,
HireDate = @"2014-01-22",
ID = 18,
Name = @"Victoria Lincoln",
Phone = @"(071) 23 67 22 20",
OnPTO = true,
ParentID = -1,
Title = @"Accounting Manager"
});
this.Add(new EmployeesFlatDataItem()
{
Age = 61,
HireDate = @"2010-01-01",
ID = 10,
Name = @"Yang Wang",
Phone = @"(21) 555-0091",
OnPTO = false,
ParentID = -1,
Title = @"Localization Manager"
});
this.Add(new EmployeesFlatDataItem()
{
Age = 43,
HireDate = @"2011-06-03",
ID = 3,
Name = @"Michael Burke",
Phone = @"0452-076545",
OnPTO = true,
ParentID = 1,
Title = @"Senior Software Developer"
});
this.Add(new EmployeesFlatDataItem()
{
Age = 29,
HireDate = @"2009-06-19",
ID = 2,
Name = @"Thomas Anderson",
Phone = @"(14) 555-8122",
OnPTO = false,
ParentID = 1,
Title = @"Senior Software Developer"
});
this.Add(new EmployeesFlatDataItem()
{
Age = 31,
HireDate = @"2014-08-18",
ID = 11,
Name = @"Monica Reyes",
Phone = @"7675-3425",
OnPTO = false,
ParentID = 1,
Title = @"Software Development Team Lead"
});
this.Add(new EmployeesFlatDataItem()
{
Age = 35,
HireDate = @"2015-09-17",
ID = 6,
Name = @"Roland Mendel",
Phone = @"(505) 555-5939",
OnPTO = false,
ParentID = 11,
Title = @"Senior Software Developer"
});
this.Add(new EmployeesFlatDataItem()
{
Age = 44,
HireDate = @"2009-10-11",
ID = 12,
Name = @"Sven Cooper",
Phone = @"0695-34 67 21",
OnPTO = true,
ParentID = 11,
Title = @"Senior Software Developer"
});
this.Add(new EmployeesFlatDataItem()
{
Age = 44,
HireDate = @"2014-04-04",
ID = 14,
Name = @"Laurence Johnson",
Phone = @"981-443655",
OnPTO = false,
ParentID = 4,
Title = @"Director"
});
this.Add(new EmployeesFlatDataItem()
{
Age = 25,
HireDate = @"2017-11-09",
ID = 5,
Name = @"Elizabeth Richards",
Phone = @"(2) 283-2951",
OnPTO = true,
ParentID = 4,
Title = @"Vice President"
});
this.Add(new EmployeesFlatDataItem()
{
Age = 39,
HireDate = @"2010-03-22",
ID = 13,
Name = @"Trevor Ashworth",
Phone = @"981-443655",
OnPTO = true,
ParentID = 5,
Title = @"Director"
});
this.Add(new EmployeesFlatDataItem()
{
Age = 44,
HireDate = @"2014-04-04",
ID = 17,
Name = @"Antonio Moreno",
Phone = @"(505) 555-5939",
OnPTO = false,
ParentID = 18,
Title = @"Senior Accountant"
});
this.Add(new EmployeesFlatDataItem()
{
Age = 50,
HireDate = @"2007-11-18",
ID = 7,
Name = @"Pedro Rodriguez",
Phone = @"035-640230",
OnPTO = false,
ParentID = 10,
Title = @"Senior Localization Developer"
});
this.Add(new EmployeesFlatDataItem()
{
Age = 27,
HireDate = @"2016-02-19",
ID = 8,
Name = @"Casey Harper",
Phone = @"0342-023176",
OnPTO = true,
ParentID = 10,
Title = @"Senior Localization"
});
this.Add(new EmployeesFlatDataItem()
{
Age = 25,
HireDate = @"2017-11-09",
ID = 15,
Name = @"Patricia Simpson",
Phone = @"069-0245984",
OnPTO = false,
ParentID = 7,
Title = @"Localization Intern"
});
this.Add(new EmployeesFlatDataItem()
{
Age = 39,
HireDate = @"2010-03-22",
ID = 9,
Name = @"Francisco Chang",
Phone = @"(91) 745 6200",
OnPTO = false,
ParentID = 7,
Title = @"Localization Intern"
});
this.Add(new EmployeesFlatDataItem()
{
Age = 25,
HireDate = @"2018-03-18",
ID = 16,
Name = @"Peter Lewis",
Phone = @"069-0245984",
OnPTO = true,
ParentID = 7,
Title = @"Localization Intern"
});
}
}
cs
@using IgniteUI.Blazor.Controls
<style>
/*
CSS styles are loaded from the shared CSS file located at:
https://static.infragistics.com/xplatform/css/samples/
*/
.gridSize {
--ig-size: var(--ig-size-small);
}
</style>
<div class="container vertical ig-typography">
<div class="container vertical fill">
<IgbTreeGrid
Class="gridSize"
AutoGenerate="false"
Height="620px"
Name="treeGrid"
@ref="treeGrid"
Id="treeGrid"
Data="EmployeesFlatData"
PrimaryKey="ID"
ForeignKey="ParentID"
ColumnInitScript="WebTreeGridCustomSummary">
<IgbColumn
Field="Name"
DataType="GridColumnDataType.String">
</IgbColumn>
<IgbColumn Field="Age"
DataType="GridColumnDataType.Number">
</IgbColumn>
<IgbColumn
Field="Title"
DataType="GridColumnDataType.String"
HasSummary="true">
</IgbColumn>
<IgbColumn
Field="HireDate"
DataType="GridColumnDataType.Date"
HasSummary="true">
</IgbColumn>
<IgbColumn
Field="OnPTO"
DataType="GridColumnDataType.Boolean"
HasSummary="true">
</IgbColumn>
</IgbTreeGrid>
</div>
</div>
@code {
protected override async Task OnAfterRenderAsync(bool firstRender)
{
var treeGrid = this.treeGrid;
}
private IgbTreeGrid treeGrid;
private EmployeesFlatData _employeesFlatData = null;
public EmployeesFlatData EmployeesFlatData
{
get
{
if (_employeesFlatData == null)
{
_employeesFlatData = new EmployeesFlatData();
}
return _employeesFlatData;
}
}
}
razor
class PtoSummary {
count(data) {
return data.length;
};
operate(data, allData, fieldName) {
const result = [];
result.push({
key: 'totalOnPTO',
label: 'Employees On PTO',
summaryResult: this.count(allData.filter((rec) => rec['OnPTO']).map(r => r[fieldName]))
});
result.push({
key: 'devs',
label: 'Developers',
summaryResult: this.count(allData.filter((rec) => rec[fieldName].includes('Developer') && rec['OnPTO']).map(r => r[fieldName]))
});
result.push({
key: 'tl',
label: 'Team Leads',
summaryResult: this.count(allData.filter((rec) => rec[fieldName].includes('Team Lead') && rec['OnPTO']).map(r => r[fieldName]))
});
result.push({
key: 'managers',
label: 'Managers/Directors',
summaryResult: this.count(allData.filter((rec) => (rec[fieldName].includes('Manager') || rec[fieldName].includes('Director')) && rec['OnPTO']).map(r => r[fieldName]))
});
result.push({
key: 'ceo',
label: 'CEO/President',
summaryResult: this.count(allData.filter((rec) => (rec[fieldName].includes('CEO') || rec[fieldName].includes('President')) && rec['OnPTO']).map(r => r[fieldName]))
});
return result;
}
}
igRegisterScript("WebTreeGridCustomSummary", (event) => {
if (event.detail.field === "Title") {
event.detail.summaries = PtoSummary;
}
}, false);
js/*
CSS styles are loaded from the shared CSS file located at:
https://static.infragistics.com/xplatform/css/samples/
*/
.gridSize {
--ig-size: var(--ig-size-small);
}
css
Summary Template
SummaryTemplate
targets the column summary providing as a context the column summary results.
<IgbColumn HasSummary="true" SummaryTemplateScript="SummaryTemplate">
</IgbColumn>
igRegisterScript("SummaryTemplate", (ctx) => {
var html = window.igTemplating.html;
return html`<div>
<span> ${ctx.implicit[0].label} - ${ctx.implicit[0].summaryResult} </span>
</div>`
}, false);
razor
When a default summary is defined, the height of the summary area is calculated by design depending on the column with the largest number of summaries and the --ig-size
of the grid. Use the SummaryRowHeight
input property to override the default value. As an argument it expects a number value, and setting a falsy value will trigger the default sizing behavior of the grid footer.
using System;
using System.Net.Http;
using System.Collections.Generic;
using System.Threading.Tasks;
using System.Text;
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using IgniteUI.Blazor.Controls; // for registering Ignite UI modules
namespace Infragistics.Samples
{
public class Program
{
public static async Task Main(string[] args)
{
var builder = WebAssemblyHostBuilder.CreateDefault(args);
builder.RootComponents.Add<App>("app");
builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) });
// registering Ignite UI modules
builder.Services.AddIgniteUIBlazor(
typeof(IgbInputModule),
typeof(IgbPropertyEditorPanelModule),
typeof(IgbTreeGridModule)
);
await builder.Build().RunAsync();
}
}
}
csusing System;
using System.Collections.Generic;
public class EmployeesNestedTreeDataItem
{
public double Age { get; set; }
public string HireDate { get; set; }
public double ID { get; set; }
public string Name { get; set; }
public string Phone { get; set; }
public bool OnPTO { get; set; }
public double ParentID { get; set; }
public string Title { get; set; }
}
public class EmployeesNestedTreeData
: List<EmployeesNestedTreeDataItem>
{
public EmployeesNestedTreeData()
{
this.Add(new EmployeesNestedTreeDataItem()
{
Age = 55,
HireDate = @"2008-03-20",
ID = 1,
Name = @"Johnathan Winchester",
Phone = @"0251-031259",
OnPTO = false,
ParentID = -1,
Title = @"Development Manager"
});
this.Add(new EmployeesNestedTreeDataItem()
{
Age = 42,
HireDate = @"2014-01-22",
ID = 4,
Name = @"Ana Sanders",
Phone = @"(21) 555-0091",
OnPTO = true,
ParentID = -1,
Title = @"CEO"
});
this.Add(new EmployeesNestedTreeDataItem()
{
Age = 49,
HireDate = @"2014-01-22",
ID = 18,
Name = @"Victoria Lincoln",
Phone = @"(071) 23 67 22 20",
OnPTO = true,
ParentID = -1,
Title = @"Accounting Manager"
});
this.Add(new EmployeesNestedTreeDataItem()
{
Age = 61,
HireDate = @"2010-01-01",
ID = 10,
Name = @"Yang Wang",
Phone = @"(21) 555-0091",
OnPTO = false,
ParentID = -1,
Title = @"Localization Manager"
});
this.Add(new EmployeesNestedTreeDataItem()
{
Age = 43,
HireDate = @"2011-06-03",
ID = 3,
Name = @"Michael Burke",
Phone = @"0452-076545",
OnPTO = true,
ParentID = 1,
Title = @"Senior Software Developer"
});
this.Add(new EmployeesNestedTreeDataItem()
{
Age = 29,
HireDate = @"2009-06-19",
ID = 2,
Name = @"Thomas Anderson",
Phone = @"(14) 555-8122",
OnPTO = false,
ParentID = 1,
Title = @"Senior Software Developer"
});
this.Add(new EmployeesNestedTreeDataItem()
{
Age = 31,
HireDate = @"2014-08-18",
ID = 11,
Name = @"Monica Reyes",
Phone = @"7675-3425",
OnPTO = false,
ParentID = 1,
Title = @"Software Development Team Lead"
});
this.Add(new EmployeesNestedTreeDataItem()
{
Age = 35,
HireDate = @"2015-09-17",
ID = 6,
Name = @"Roland Mendel",
Phone = @"(505) 555-5939",
OnPTO = false,
ParentID = 11,
Title = @"Senior Software Developer"
});
this.Add(new EmployeesNestedTreeDataItem()
{
Age = 44,
HireDate = @"2009-10-11",
ID = 12,
Name = @"Sven Cooper",
Phone = @"0695-34 67 21",
OnPTO = true,
ParentID = 11,
Title = @"Senior Software Developer"
});
this.Add(new EmployeesNestedTreeDataItem()
{
Age = 44,
HireDate = @"2014-04-04",
ID = 14,
Name = @"Laurence Johnson",
Phone = @"981-443655",
OnPTO = false,
ParentID = 4,
Title = @"Director"
});
this.Add(new EmployeesNestedTreeDataItem()
{
Age = 25,
HireDate = @"2017-11-09",
ID = 5,
Name = @"Elizabeth Richards",
Phone = @"(2) 283-2951",
OnPTO = true,
ParentID = 4,
Title = @"Vice President"
});
this.Add(new EmployeesNestedTreeDataItem()
{
Age = 39,
HireDate = @"2010-03-22",
ID = 13,
Name = @"Trevor Ashworth",
Phone = @"981-443655",
OnPTO = true,
ParentID = 5,
Title = @"Director"
});
this.Add(new EmployeesNestedTreeDataItem()
{
Age = 44,
HireDate = @"2014-04-04",
ID = 17,
Name = @"Antonio Moreno",
Phone = @"(505) 555-5939",
OnPTO = false,
ParentID = 18,
Title = @"Senior Accountant"
});
this.Add(new EmployeesNestedTreeDataItem()
{
Age = 50,
HireDate = @"2007-11-18",
ID = 7,
Name = @"Pedro Rodriguez",
Phone = @"035-640230",
OnPTO = false,
ParentID = 10,
Title = @"Senior Localization Developer"
});
this.Add(new EmployeesNestedTreeDataItem()
{
Age = 27,
HireDate = @"2016-02-19",
ID = 8,
Name = @"Casey Harper",
Phone = @"0342-023176",
OnPTO = true,
ParentID = 10,
Title = @"Senior Localization"
});
this.Add(new EmployeesNestedTreeDataItem()
{
Age = 25,
HireDate = @"2017-11-09",
ID = 15,
Name = @"Patricia Simpson",
Phone = @"069-0245984",
OnPTO = false,
ParentID = 7,
Title = @"Localization Intern"
});
this.Add(new EmployeesNestedTreeDataItem()
{
Age = 39,
HireDate = @"2010-03-22",
ID = 9,
Name = @"Francisco Chang",
Phone = @"(91) 745 6200",
OnPTO = false,
ParentID = 7,
Title = @"Localization Intern"
});
this.Add(new EmployeesNestedTreeDataItem()
{
Age = 25,
HireDate = @"2018-03-18",
ID = 16,
Name = @"Peter Lewis",
Phone = @"069-0245984",
OnPTO = true,
ParentID = 7,
Title = @"Localization Intern"
});
}
}
cs
@using IgniteUI.Blazor.Controls
@inject IJSRuntime JS
<div class="container vertical ig-typography">
<div class="options vertical">
<IgbPropertyEditorPanel
DescriptionType="WebTreeGrid"
IsHorizontal="true"
IsWrappingEnabled="false"
Name="propertyEditorPanel1"
@ref="propertyEditorPanel1">
<IgbPropertyEditorPropertyDescription
PropertyPath="SummaryRowHeight"
Label="Summary Row Height"
ValueType="PropertyEditorValueType.Number"
Name="SummaryRowHeightEditor"
@ref="summaryRowHeightEditor">
</IgbPropertyEditorPropertyDescription>
<IgbPropertyEditorPropertyDescription
Label="Toggle Summaries"
ValueType="PropertyEditorValueType.Boolean1"
PrimitiveValue="true"
Changed="WebTreeGridHasSummariesChange"
Name="ToggleSummariesEditor"
@ref="toggleSummariesEditor">
</IgbPropertyEditorPropertyDescription>
<IgbPropertyEditorPropertyDescription
Name="SizeEditor"
@ref="sizeEditor"
Label="Grid Size:"
ValueType="PropertyEditorValueType.EnumValue"
DropDownNames="@(new string[] { "Small", "Medium", "Large" })"
DropDownValues="@(new string[] { "Small", "Medium", "Large" })"
ChangedScript="WebTreeGridSetGridSize">
</IgbPropertyEditorPropertyDescription>
</IgbPropertyEditorPanel>
</div>
<div class="container vertical fill">
<IgbTreeGrid
AutoGenerate="false"
Data="EmployeesNestedTreeData"
Name="treeGrid"
@ref="treeGrid"
Id="treeGrid"
PrimaryKey="ID"
ForeignKey="ParentID">
<IgbColumn
Field="Name">
</IgbColumn>
<IgbColumn
Field="Age"
DataType="GridColumnDataType.Number"
HasSummary="true"
SummaryTemplateScript="WebTreeGridSummaryTemplate"
Name="column1"
@ref="column1">
</IgbColumn>
<IgbColumn
Field="Title"
HasSummary="true">
</IgbColumn>
<IgbColumn
Field="HireDate"
DataType="GridColumnDataType.Date">
</IgbColumn>
<IgbColumn
Field="OnPTO"
DataType="GridColumnDataType.Boolean"
Editable="true"
HasSummary="true">
</IgbColumn>
</IgbTreeGrid>
</div>
</div>
@code {
private Action BindElements { get; set; }
protected override async Task OnAfterRenderAsync(bool firstRender)
{
var propertyEditorPanel1 = this.propertyEditorPanel1;
var summaryRowHeightEditor = this.summaryRowHeightEditor;
var toggleSummariesEditor = this.toggleSummariesEditor;
var sizeEditor = this.sizeEditor;
var treeGrid = this.treeGrid;
var column1 = this.column1;
this.BindElements = () => {
propertyEditorPanel1.Target = this.treeGrid;
};
this.BindElements();
}
private IgbPropertyEditorPanel propertyEditorPanel1;
private IgbPropertyEditorPropertyDescription summaryRowHeightEditor;
private IgbPropertyEditorPropertyDescription toggleSummariesEditor;
private IgbPropertyEditorPropertyDescription sizeEditor;
private IgbTreeGrid treeGrid;
private IgbColumn column1;
public void WebTreeGridHasSummariesChange(IgbPropertyEditorPropertyDescriptionChangedEventArgs args)
{
bool newValue = bool.Parse(args.NewValue.ToString());
var treeGrid = this.treeGrid;
var column1 = treeGrid.GetColumns().ElementAt(1);
var column2 = treeGrid.GetColumns().ElementAt(2);
var column3 = treeGrid.GetColumns().ElementAt(4);
column1.HasSummary = newValue;
column2.HasSummary = newValue;
column3.HasSummary = newValue;
}
private EmployeesNestedTreeData _employeesNestedTreeData = null;
public EmployeesNestedTreeData EmployeesNestedTreeData
{
get
{
if (_employeesNestedTreeData == null)
{
_employeesNestedTreeData = new EmployeesNestedTreeData();
}
return _employeesNestedTreeData;
}
}
}
razor
igRegisterScript("WebTreeGridSummaryTemplate", (ctx) => {
const style = document.createElement('style');
style.innerHTML = `
.summary-temp {
display: flex;
flex-direction: column;
margin: 0 1px;
font-size: 14px;
line-height: 24px;
height: 100%;
overflow-y: auto;
overflow-x: hidden;
> * {
padding: 8px 0;
line-height: 18px;
border-bottom: 1px dashed hsla(var(--igx-gray-400));
&:last-child {
border - bottom: none;
}
}
}
.summary-temp span {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 4px;
justify-content: space-between;
color: hsla(var(--ig-gray-900));
}
.summary-temp span span {
user - select: all;
max-width: 300px;
padding-right: 8px;
}
.summary-temp span strong {
font - size: 12px;
text-transform: uppercase;
min-width: 70px;
justify-self: flex-start;
text-align: left;
color: hsla(var(--ig-secondary-600));
user-select: none;
}
`;
document.head.appendChild(style);
var html = window.igTemplating.html;
var summaryResults = ctx.implicit;
return html`<div class="summary-temp">
<span><strong>${summaryResults[0].label}</strong><span>${summaryResults[0].summaryResult}</span></span>
<span><strong>${summaryResults[1].label}</strong><span>${summaryResults[1].summaryResult}</span></span>
<span><strong>${summaryResults[2].label}</strong><span>${summaryResults[2].summaryResult}</span></span>
<span><strong>${summaryResults[3].label}</strong><span>${summaryResults[3].summaryResult}</span></span>
</div>`;
}, false);
igRegisterScript("WebTreeGridSetGridSize", (sender, evtArgs) => {
var newVal = evtArgs.newValue.toLowerCase();
var grid = document.getElementById("treeGrid");
grid.style.setProperty('--ig-size', `var(--ig-size-${newVal})`);
}, false);
js/*
CSS styles are loaded from the shared CSS file located at:
https://static.infragistics.com/xplatform/css/samples/
*/
css
Disabled Summaries
The DisabledSummaries
property provides precise per-column control over the Blazor Tree Grid summary feature. This property enables users to customize the summaries displayed for each column in the TreeGrid, ensuring that only the most relevant and meaningful data is shown. For example, you can exclude specific summary types, such as ['count', 'min', 'max']
by specifying their summary keys in an array.
This property can also be modified dynamically at runtime through code, providing flexibility to adapt the TreeGrid's summaries to changing application states or user actions.
The following examples illustrate how to use the DisabledSummaries
property to manage summaries for different columns and exclude specific default and custom summary types in the Blazor Tree Grid:
<!-- Disable default summaries -->
<IgbColumn
Field="UnitPrice"
Header="Unit Price"
DataType="GridColumnDataType.Number"
HasSummary="true"
DisabledSummaries="['count', 'sum', 'average']" />
<!-- Disable custom summaries -->
<IgbColumn
Field="UnitsInStock"
Header="Units In Stock"
DataType="GridColumnDataType.Number"
HasSummary="true"
Summaries="discontinuedSummary"
DisabledSummaries="['discontinued', 'totalDiscontinued']" />
razor
For UnitPrice
, default summaries like count
, sum
, and average
are disabled, leaving others like min
and max
active.
For UnitsInStock
, custom summaries such as discontinued
and totalDiscontinued
are excluded using the DisabledSummaries
property.
At runtime, summaries can also be dynamically disabled using the DisabledSummaries
property. For example, you can set or update the property on specific columns programmatically to adapt the displayed summaries based on user actions or application state changes.
using System;
using System.Net.Http;
using System.Collections.Generic;
using System.Threading.Tasks;
using System.Text;
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using IgniteUI.Blazor.Controls; // for registering Ignite UI modules
namespace Infragistics.Samples
{
public class Program
{
public static async Task Main(string[] args)
{
var builder = WebAssemblyHostBuilder.CreateDefault(args);
builder.RootComponents.Add<App>("app");
builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) });
// registering Ignite UI modules
builder.Services.AddIgniteUIBlazor(
typeof(IgbInputModule),
typeof(IgbTreeGridModule)
);
await builder.Build().RunAsync();
}
}
}
csusing System;
using System.Collections.Generic;
public class OrdersTreeDataItem
{
public double ID { get; set; }
public double ParentID { get; set; }
public string Name { get; set; }
public string Category { get; set; }
public string OrderDate { get; set; }
public double Units { get; set; }
public double UnitPrice { get; set; }
public double Price { get; set; }
public bool Delivered { get; set; }
}
public class OrdersTreeData
: List<OrdersTreeDataItem>
{
public OrdersTreeData()
{
this.Add(new OrdersTreeDataItem()
{
ID = 1,
ParentID = -1,
Name = @"Order 1",
Category = @"",
OrderDate = @"2010-02-17",
Units = 1844,
UnitPrice = 3.73,
Price = 6884.38,
Delivered = true
});
this.Add(new OrdersTreeDataItem()
{
ID = 101,
ParentID = 1,
Name = @"Chocolate Chip Cookies",
Category = @"Cookies",
OrderDate = @"2010-02-17",
Units = 834,
UnitPrice = 3.59,
Price = 2994.06,
Delivered = true
});
this.Add(new OrdersTreeDataItem()
{
ID = 102,
ParentID = 1,
Name = @"Red Apples",
Category = @"Fruit",
OrderDate = @"2010-02-17",
Units = 371,
UnitPrice = 3.66,
Price = 1357.86,
Delivered = true
});
this.Add(new OrdersTreeDataItem()
{
ID = 103,
ParentID = 1,
Name = @"Butter",
Category = @"Diary",
OrderDate = @"2010-02-17",
Units = 260,
UnitPrice = 3.45,
Price = 897,
Delivered = true
});
this.Add(new OrdersTreeDataItem()
{
ID = 104,
ParentID = 1,
Name = @"Potato Chips",
Category = @"Snack",
OrderDate = @"2010-02-17",
Units = 118,
UnitPrice = 1.96,
Price = 231.28,
Delivered = true
});
this.Add(new OrdersTreeDataItem()
{
ID = 105,
ParentID = 1,
Name = @"Orange Juice",
Category = @"Beverages",
OrderDate = @"2010-02-17",
Units = 261,
UnitPrice = 5.38,
Price = 1404.18,
Delivered = true
});
this.Add(new OrdersTreeDataItem()
{
ID = 2,
ParentID = -1,
Name = @"Order 2",
Category = @"",
OrderDate = @"2022-05-27",
Units = 1831,
UnitPrice = 8.23,
Price = 15062.77,
Delivered = false
});
this.Add(new OrdersTreeDataItem()
{
ID = 201,
ParentID = 2,
Name = @"Frozen Shrimps",
Category = @"Seafood",
OrderDate = @"2022-05-27",
Units = 120,
UnitPrice = 20.45,
Price = 2454,
Delivered = false
});
this.Add(new OrdersTreeDataItem()
{
ID = 202,
ParentID = 2,
Name = @"Ice Tea",
Category = @"Beverages",
OrderDate = @"2022-05-27",
Units = 840,
UnitPrice = 7,
Price = 5880,
Delivered = false
});
this.Add(new OrdersTreeDataItem()
{
ID = 203,
ParentID = 2,
Name = @"Fresh Cheese",
Category = @"Diary",
OrderDate = @"2022-05-27",
Units = 267,
UnitPrice = 16.55,
Price = 4418.85,
Delivered = false
});
this.Add(new OrdersTreeDataItem()
{
ID = 204,
ParentID = 2,
Name = @"Carrots",
Category = @"Vegetables",
OrderDate = @"2022-05-27",
Units = 360,
UnitPrice = 2.77,
Price = 997.2,
Delivered = false
});
this.Add(new OrdersTreeDataItem()
{
ID = 205,
ParentID = 2,
Name = @"Apple Juice",
Category = @"Beverages",
OrderDate = @"2022-05-27",
Units = 244,
UnitPrice = 5.38,
Price = 1312.72,
Delivered = false
});
this.Add(new OrdersTreeDataItem()
{
ID = 3,
ParentID = -1,
Name = @"Order 3",
Category = @"",
OrderDate = @"2022-08-04",
Units = 1972,
UnitPrice = 3.47,
Price = 6849.18,
Delivered = true
});
this.Add(new OrdersTreeDataItem()
{
ID = 301,
ParentID = 3,
Name = @"Skimmed Milk 1L",
Category = @"Diary",
OrderDate = @"2022-08-04",
Units = 1028,
UnitPrice = 3.56,
Price = 3659.68,
Delivered = true
});
this.Add(new OrdersTreeDataItem()
{
ID = 302,
ParentID = 3,
Name = @"Bananas 5 Pack",
Category = @"Fruit",
OrderDate = @"2022-08-04",
Units = 370,
UnitPrice = 6.36,
Price = 2353.2,
Delivered = true
});
this.Add(new OrdersTreeDataItem()
{
ID = 303,
ParentID = 3,
Name = @"Cauliflower",
Category = @"Vegetables",
OrderDate = @"2022-08-04",
Units = 283,
UnitPrice = 0.95,
Price = 268.85,
Delivered = true
});
this.Add(new OrdersTreeDataItem()
{
ID = 304,
ParentID = 3,
Name = @"White Chocolate Cookies",
Category = @"Cookies",
OrderDate = @"2022-08-04",
Units = 291,
UnitPrice = 1.95,
Price = 567.45,
Delivered = true
});
this.Add(new OrdersTreeDataItem()
{
ID = 4,
ParentID = -1,
Name = @"Order 4",
Category = @"",
OrderDate = @"2023-01-04",
Units = 1065,
UnitPrice = 5.56,
Price = 5923.5,
Delivered = true
});
this.Add(new OrdersTreeDataItem()
{
ID = 401,
ParentID = 4,
Name = @"Mini Milk Chocolate Cookie Bites",
Category = @"Cookies",
OrderDate = @"2023-01-04",
Units = 68,
UnitPrice = 2.25,
Price = 153,
Delivered = true
});
this.Add(new OrdersTreeDataItem()
{
ID = 402,
ParentID = 4,
Name = @"Wild Salmon Fillets",
Category = @"Seafood",
OrderDate = @"2023-01-04",
Units = 320,
UnitPrice = 16.15,
Price = 5168,
Delivered = true
});
this.Add(new OrdersTreeDataItem()
{
ID = 403,
ParentID = 4,
Name = @"Diet Lemonade",
Category = @"Beverages",
OrderDate = @"2023-01-04",
Units = 437,
UnitPrice = 0.5,
Price = 218.5,
Delivered = true
});
this.Add(new OrdersTreeDataItem()
{
ID = 404,
ParentID = 4,
Name = @"Potatoes",
Category = @"Vegetables",
OrderDate = @"2023-01-04",
Units = 240,
UnitPrice = 1.6,
Price = 384,
Delivered = true
});
}
}
cs
@using IgniteUI.Blazor.Controls
@inject IJSRuntime JS
<style>
/*
CSS styles are loaded from the shared CSS file located at:
https://static.infragistics.com/xplatform/css/samples/
*/
.fill {
padding: 16px;
}
.summaries-buttons {
margin: 1rem 0;
display: flex;
align-items: center;
flex-wrap: wrap;
}
.summaries-title {
font-weight: bold;
}
.summary-button {
margin-right: 1rem;
}
igc-dialog::part(title) {
color: #1E6DFE;
}
.summaries-dialog-items {
display: flex;
flex-direction: column;
align-items: flex-start;
}
.summaries-dialog-items igc-checkbox {
display: flex;
flex-direction: column;
align-items: flex-start;
}
</style>
<div class="container vertical ig-typography">
<div class="container vertical fill">
<div class="wrapper">
<span class="summaries-title">Disable Summaries for Column:</span>
<div class="summaries-buttons">
@if (treeGrid != null && columns?.Length > 0)
{
@foreach (IgbColumn column in columns)
{
<IgbButton Variant="ButtonVariant.Contained" class="summary-button"
@onclick="() => OnDialogShow(column)">@column.Header</IgbButton>
}
}
</div>
<IgbDialog @ref="dialog" Title="@dialogTitle" CloseOnOutsideClick="true">
<div class="summaries-dialog-items">
@if (currentColumn != null && currentColumn.HasSummary && summaries.Count() > 0)
{
@foreach (var summary in this.summaries)
{
<IgbCheckbox Value="@summary.Key" Checked="@currentColDisabledSummaries.Contains(summary.Key)"
Change="@((evt) => ToggleSummary(evt))">@summary.Value</IgbCheckbox>
}
}
</div>
<IgbButton slot="footer" Variant=@ButtonVariant.Flat Disabled="currentColDisabledSummaries.Count == summaries.Count()"
@onclick="() => ToggleAllSummaries(false)">Disable All</IgbButton>
<IgbButton slot="footer" Variant=@ButtonVariant.Flat Disabled="currentColDisabledSummaries.Count == 0"
@onclick="() => ToggleAllSummaries(true)">Enable All</IgbButton>
</IgbDialog>
<IgbTreeGrid AutoGenerate="false"
Data="OrdersTreeData"
Name="treeGrid"
@ref="treeGrid"
Id="treeGrid"
PrimaryKey="ID"
ForeignKey="ParentID"
ColumnInitScript="ColumnInitScript">
<IgbColumn Field="ID"
Header="Order ID"
@ref="orderID"
HasSummary="true">
</IgbColumn>
<IgbColumn Field="Name"
Header="Order Product"
HasSummary="true"
Name="Order Product"
@ref="orderProduct">
</IgbColumn>
<IgbColumn Field="Units"
Header="Units"
DataType="GridColumnDataType.Number"
HasSummary="true"
Editable="true"
HeaderTemplateScript="WebTreeGridSummariesHeaderTemplate"
Name="Units"
@ref="units">
</IgbColumn>
<IgbColumn Field="UnitPrice"
Header="Unit Price"
DataType="GridColumnDataType.Number"
HasSummary="true"
Editable="true"
HeaderTemplateScript="WebTreeGridSummariesHeaderTemplate"
Name="Unit Price"
@ref="unitPrice">
</IgbColumn>
<IgbColumn Field="Price"
Header="Price"
DataType="GridColumnDataType.Number"
HasSummary="true"
Editable="true"
HeaderTemplateScript="WebTreeGridSummariesHeaderTemplate"
Name="Price"
@ref="price">
</IgbColumn>
<IgbColumn Field="Delivered"
Header="Delivered"
DataType="GridColumnDataType.Boolean"
HasSummary="true"
HeaderTemplateScript="WebTreeGridSummariesHeaderTemplate"
Name="Delivered"
@ref="delivered">
</IgbColumn>
<IgbColumn Field="OrderDate"
Header="Order Date"
DataType="GridColumnDataType.Date"
HasSummary="true"
HeaderTemplateScript="WebTreeGridSummariesHeaderTemplate"
Name="Order Date"
@ref="orderDate">
</IgbColumn>
</IgbTreeGrid>
</div>
</div>
</div>
@code {
private IgbTreeGrid treeGrid;
private IgbColumn orderID;
private IgbColumn orderProduct;
private IgbColumn units;
private IgbColumn unitPrice;
private IgbColumn price;
private IgbColumn delivered;
private IgbColumn orderDate;
private IgbColumn[] columns { get; set; } = [];
private IgbColumn currentColumn;
private Dictionary<string, string> summaries = [];
private List<string> currentColDisabledSummaries { get; set; } = new List<string>();
private IgbDialog dialog;
private string dialogTitle;
private OrdersTreeData _ordersTreeData = null;
public OrdersTreeData OrdersTreeData
{
get
{
if (_ordersTreeData == null)
{
_ordersTreeData = new OrdersTreeData();
}
return _ordersTreeData;
}
}
protected override async Task OnAfterRenderAsync(bool firstRender)
{
if (firstRender)
{
if (treeGrid != null)
{
columns = new IgbColumn[] { orderID, orderProduct, units, unitPrice, price, delivered, orderDate };
StateHasChanged();
}
}
}
public async Task OnDialogShow(IgbColumn column)
{
if (this.dialog != null)
{
this.currentColumn = column;
this.dialogTitle = "Disable Summaries for: " + column.Header;
this.currentColDisabledSummaries.Clear();
if (currentColumn.DisabledSummaries != null)
{
this.currentColDisabledSummaries = currentColumn.DisabledSummaries.ToList();
}
await this.GetSummaryKeysAsync();
await this.dialog.ShowAsync();
}
}
private async Task GetSummaryKeysAsync()
{
if (currentColumn != null && currentColumn.HasSummary)
{
summaries = await JS.InvokeAsync<Dictionary<string, string>>("getSummaries", currentColumn.Field);
StateHasChanged();
}
}
public async Task ToggleSummary(IgbCheckboxChangeEventArgs eventArgs)
{
if (currentColumn != null && currentColumn.HasSummary)
{
string summaryKey = eventArgs.Detail.Value;
if (eventArgs.Detail.Checked && !currentColDisabledSummaries.Contains(summaryKey))
{
currentColDisabledSummaries.Add(summaryKey);
}
else if (!eventArgs.Detail.Checked && currentColDisabledSummaries.Contains(summaryKey))
{
currentColDisabledSummaries.Remove(eventArgs.Detail.Value);
}
currentColumn.DisabledSummaries = currentColDisabledSummaries.ToArray();
}
}
public async Task ToggleAllSummaries(bool enable)
{
if (currentColumn != null && currentColumn.HasSummary)
{
if (enable)
{
currentColDisabledSummaries.Clear();
}
else
{
currentColDisabledSummaries = summaries.Keys.ToList();
}
currentColumn.DisabledSummaries = currentColDisabledSummaries.ToArray();
}
}
}
razorclass UnitsSummary {
operate(data, allData, fieldName) {
const result = [];
const values = allData.map((rec) => rec[fieldName]).filter((value) => value !== undefined && value !== null);
const totalSum = values.reduce((sum, value) => sum + value, 0);
const sortedValues = values.slice().sort((a, b) => a - b);
const deliveredValues = allData
.filter((rec) => rec["Delivered"])
.map((rec) => rec[fieldName])
.filter((value) => value !== undefined && value !== null);
result.push({
key: "count",
label: "Count",
summaryResult: allData.length
});
result.push({
key: "min",
label: "Min",
summaryResult: values.length > 0 ? Math.min(...values) : "N/A"
});
result.push({
key: "max",
label: "Max",
summaryResult: values.length > 0 ? Math.max(...values) : "N/A"
});
result.push({
key: "sum",
label: "Sum",
summaryResult: totalSum
});
result.push({
key: "average",
label: "Average",
summaryResult: values.length > 0 ? totalSum / values.length : "N/A"
});
result.push({
key: "totalDelivered",
label: "Total Units Delivered",
summaryResult: deliveredValues.length > 0 ? deliveredValues.reduce((sum, value) => sum + value, 0) : "N/A"
});
result.push({
key: "medianUnits",
label: "Median Units",
summaryResult:
values.length > 0
? (() => {
const mid = Math.floor(sortedValues.length / 2);
return sortedValues.length % 2 !== 0 ? sortedValues[mid] : (sortedValues[mid - 1] + sortedValues[mid]) / 2;
})()
: "N/A"
});
result.push({
key: "uniqueCount",
label: "Count of Unique Unit Values",
summaryResult: values.length > 0 ? new Set(values).size : "N/A"
});
result.push({
key: "maxDifference",
label: "Max Difference Between Units",
summaryResult:
values.length > 1
? values.reduce((maxDiff, value, idx, arr) => {
if (idx === 0) return maxDiff;
const diff = Math.abs(value - arr[idx - 1]);
return Math.max(maxDiff, diff);
}, 0)
: "N/A"
});
return result;
}
}
igRegisterScript("ColumnInitScript", (event) => {
if (event.detail.field === "Units") {
event.detail.summaries = UnitsSummary;
}
}, false);
window.getSummaries = (field) => {
const grid = document.getElementById("treeGrid");
const col = grid.getColumnByName(field);
const summaryOperand = col?.summaries;
if (summaryOperand) {
let result = summaryOperand.operate([], grid.data, field).map(s => ({ [s.key]: s.label }));
return Object.assign({}, ...result);
}
return {};
};
js/*
CSS styles are loaded from the shared CSS file located at:
https://static.infragistics.com/xplatform/css/samples/
*/
.fill {
padding: 16px;
}
.summaries-buttons {
margin: 1rem 0;
display: flex;
align-items: center;
flex-wrap: wrap;
}
.summaries-title {
font-weight: bold;
}
.summary-button {
margin-right: 1rem;
}
igc-dialog::part(title) {
color: #1E6DFE;
}
.summaries-dialog-items {
display: flex;
flex-direction: column;
align-items: flex-start;
}
.summaries-dialog-items igc-checkbox {
display: flex;
flex-direction: column;
align-items: flex-start;
}
css
Child Summaries
The IgbTreeGrid
supports separate summaries for the root nodes and for each nested child node level. Which summaries are shown is configurable using the SummaryCalculationMode
property. The child level summaries can be shown before or after the child nodes using the SummaryPosition
property. Along with these two properties the IgbTreeGrid
exposes and ShowSummaryOnCollapse
property which allows you to determine whether the summary row stays visible when the parent node that refers to is collapsed.
The available values of the SummaryCalculationMode
property are:
RootLevelOnly
- Summaries are calculated only for the root level nodes.ChildLevelsOnly
- Summaries are calculated only for the child levels.RootAndChildLevels
- Summaries are calculated for both root and child levels. This is the default value.
The available values of the SummaryPosition
property are:
Top
- The summary row appears before the list of child rows.Bottom
- The summary row appears after the list of child rows. This is the default value.
The ShowSummaryOnCollapse
property is boolean. Its default value is set to false, which means that the summary row would be hidden when the parent row is collapsed. If the property is set to true the summary row stays visible when parent row is collapsed.
The SummaryPosition property applies only for the child level summaries. The root level summaries appear always fixed at the bottom of the IgbTreeGrid.
using System;
using System.Net.Http;
using System.Collections.Generic;
using System.Threading.Tasks;
using System.Text;
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using IgniteUI.Blazor.Controls; // for registering Ignite UI modules
namespace Infragistics.Samples
{
public class Program
{
public static async Task Main(string[] args)
{
var builder = WebAssemblyHostBuilder.CreateDefault(args);
builder.RootComponents.Add<App>("app");
builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) });
// registering Ignite UI modules
builder.Services.AddIgniteUIBlazor(
typeof(IgbInputModule),
typeof(IgbPropertyEditorPanelModule),
typeof(IgbTreeGridModule)
);
await builder.Build().RunAsync();
}
}
}
csusing System;
using System.Collections.Generic;
public class OrdersTreeDataItem
{
public double ID { get; set; }
public double ParentID { get; set; }
public string Name { get; set; }
public string Category { get; set; }
public string OrderDate { get; set; }
public double Units { get; set; }
public double UnitPrice { get; set; }
public double Price { get; set; }
public bool Delivered { get; set; }
}
public class OrdersTreeData
: List<OrdersTreeDataItem>
{
public OrdersTreeData()
{
this.Add(new OrdersTreeDataItem()
{
ID = 1,
ParentID = -1,
Name = @"Order 1",
Category = @"",
OrderDate = @"2010-02-17",
Units = 1844,
UnitPrice = 3.73,
Price = 6884.38,
Delivered = true
});
this.Add(new OrdersTreeDataItem()
{
ID = 101,
ParentID = 1,
Name = @"Chocolate Chip Cookies",
Category = @"Cookies",
OrderDate = @"2010-02-17",
Units = 834,
UnitPrice = 3.59,
Price = 2994.06,
Delivered = true
});
this.Add(new OrdersTreeDataItem()
{
ID = 102,
ParentID = 1,
Name = @"Red Apples",
Category = @"Fruit",
OrderDate = @"2010-02-17",
Units = 371,
UnitPrice = 3.66,
Price = 1357.86,
Delivered = true
});
this.Add(new OrdersTreeDataItem()
{
ID = 103,
ParentID = 1,
Name = @"Butter",
Category = @"Diary",
OrderDate = @"2010-02-17",
Units = 260,
UnitPrice = 3.45,
Price = 897,
Delivered = true
});
this.Add(new OrdersTreeDataItem()
{
ID = 104,
ParentID = 1,
Name = @"Potato Chips",
Category = @"Snack",
OrderDate = @"2010-02-17",
Units = 118,
UnitPrice = 1.96,
Price = 231.28,
Delivered = true
});
this.Add(new OrdersTreeDataItem()
{
ID = 105,
ParentID = 1,
Name = @"Orange Juice",
Category = @"Beverages",
OrderDate = @"2010-02-17",
Units = 261,
UnitPrice = 5.38,
Price = 1404.18,
Delivered = true
});
this.Add(new OrdersTreeDataItem()
{
ID = 2,
ParentID = -1,
Name = @"Order 2",
Category = @"",
OrderDate = @"2022-05-27",
Units = 1831,
UnitPrice = 8.23,
Price = 15062.77,
Delivered = false
});
this.Add(new OrdersTreeDataItem()
{
ID = 201,
ParentID = 2,
Name = @"Frozen Shrimps",
Category = @"Seafood",
OrderDate = @"2022-05-27",
Units = 120,
UnitPrice = 20.45,
Price = 2454,
Delivered = false
});
this.Add(new OrdersTreeDataItem()
{
ID = 202,
ParentID = 2,
Name = @"Ice Tea",
Category = @"Beverages",
OrderDate = @"2022-05-27",
Units = 840,
UnitPrice = 7,
Price = 5880,
Delivered = false
});
this.Add(new OrdersTreeDataItem()
{
ID = 203,
ParentID = 2,
Name = @"Fresh Cheese",
Category = @"Diary",
OrderDate = @"2022-05-27",
Units = 267,
UnitPrice = 16.55,
Price = 4418.85,
Delivered = false
});
this.Add(new OrdersTreeDataItem()
{
ID = 204,
ParentID = 2,
Name = @"Carrots",
Category = @"Vegetables",
OrderDate = @"2022-05-27",
Units = 360,
UnitPrice = 2.77,
Price = 997.2,
Delivered = false
});
this.Add(new OrdersTreeDataItem()
{
ID = 205,
ParentID = 2,
Name = @"Apple Juice",
Category = @"Beverages",
OrderDate = @"2022-05-27",
Units = 244,
UnitPrice = 5.38,
Price = 1312.72,
Delivered = false
});
this.Add(new OrdersTreeDataItem()
{
ID = 3,
ParentID = -1,
Name = @"Order 3",
Category = @"",
OrderDate = @"2022-08-04",
Units = 1972,
UnitPrice = 3.47,
Price = 6849.18,
Delivered = true
});
this.Add(new OrdersTreeDataItem()
{
ID = 301,
ParentID = 3,
Name = @"Skimmed Milk 1L",
Category = @"Diary",
OrderDate = @"2022-08-04",
Units = 1028,
UnitPrice = 3.56,
Price = 3659.68,
Delivered = true
});
this.Add(new OrdersTreeDataItem()
{
ID = 302,
ParentID = 3,
Name = @"Bananas 5 Pack",
Category = @"Fruit",
OrderDate = @"2022-08-04",
Units = 370,
UnitPrice = 6.36,
Price = 2353.2,
Delivered = true
});
this.Add(new OrdersTreeDataItem()
{
ID = 303,
ParentID = 3,
Name = @"Cauliflower",
Category = @"Vegetables",
OrderDate = @"2022-08-04",
Units = 283,
UnitPrice = 0.95,
Price = 268.85,
Delivered = true
});
this.Add(new OrdersTreeDataItem()
{
ID = 304,
ParentID = 3,
Name = @"White Chocolate Cookies",
Category = @"Cookies",
OrderDate = @"2022-08-04",
Units = 291,
UnitPrice = 1.95,
Price = 567.45,
Delivered = true
});
this.Add(new OrdersTreeDataItem()
{
ID = 4,
ParentID = -1,
Name = @"Order 4",
Category = @"",
OrderDate = @"2023-01-04",
Units = 1065,
UnitPrice = 5.56,
Price = 5923.5,
Delivered = true
});
this.Add(new OrdersTreeDataItem()
{
ID = 401,
ParentID = 4,
Name = @"Mini Milk Chocolate Cookie Bites",
Category = @"Cookies",
OrderDate = @"2023-01-04",
Units = 68,
UnitPrice = 2.25,
Price = 153,
Delivered = true
});
this.Add(new OrdersTreeDataItem()
{
ID = 402,
ParentID = 4,
Name = @"Wild Salmon Fillets",
Category = @"Seafood",
OrderDate = @"2023-01-04",
Units = 320,
UnitPrice = 16.15,
Price = 5168,
Delivered = true
});
this.Add(new OrdersTreeDataItem()
{
ID = 403,
ParentID = 4,
Name = @"Diet Lemonade",
Category = @"Beverages",
OrderDate = @"2023-01-04",
Units = 437,
UnitPrice = 0.5,
Price = 218.5,
Delivered = true
});
this.Add(new OrdersTreeDataItem()
{
ID = 404,
ParentID = 4,
Name = @"Potatoes",
Category = @"Vegetables",
OrderDate = @"2023-01-04",
Units = 240,
UnitPrice = 1.6,
Price = 384,
Delivered = true
});
}
}
cs
@using IgniteUI.Blazor.Controls
@inject IJSRuntime JS
<div class="container vertical ig-typography">
<div class="options vertical">
<IgbPropertyEditorPanel
DescriptionType="WebTreeGrid"
IsHorizontal="true"
IsWrappingEnabled="false"
Name="propertyEditorPanel1"
@ref="propertyEditorPanel1">
<IgbPropertyEditorPropertyDescription
Name="SummaryCalculationModeEditor"
@ref="summaryCalculationModeEditor"
Label="Summary Calculation Mode"
ValueType="PropertyEditorValueType.EnumValue"
DropDownNames="@(new string[] { "rootLevelOnly", "childLevelsOnly", "rootAndChildLevels" })"
DropDownValues="@(new string[] { "rootLevelOnly", "childLevelsOnly", "rootAndChildLevels" })"
ChangedScript="WebTreeGridChangeSummaryCalculationMode">
</IgbPropertyEditorPropertyDescription>
<IgbPropertyEditorPropertyDescription
Name="SummaryPositionEditor"
@ref="summaryPositionEditor"
Label="Summary Position"
ValueType="PropertyEditorValueType.EnumValue"
DropDownNames="@(new string[] { "top", "bottom" })"
DropDownValues="@(new string[] { "top", "bottom" })"
ChangedScript="WebTreeGridChangeSummaryPosition">
</IgbPropertyEditorPropertyDescription>
<IgbPropertyEditorPropertyDescription
Label="Show summary row when group row is collapsed:"
PropertyPath="ShowSummaryOnCollapse"
Name="ShowSummaryOnCollapseEditor"
@ref="showSummaryOnCollapseEditor">
</IgbPropertyEditorPropertyDescription>
</IgbPropertyEditorPanel>
</div>
<div class="container vertical fill">
<IgbTreeGrid
AutoGenerate="false"
Data="OrdersTreeData"
Name="treeGrid"
@ref="treeGrid"
Id="treeGrid"
PrimaryKey="ID"
ForeignKey="ParentID">
<IgbColumn
Field="ID"
Header="Order ID"
Sortable="true">
</IgbColumn>
<IgbColumn
Field="Name"
Header="Order Product"
HasSummary="true">
</IgbColumn>
<IgbColumn
Field="UnitPrice"
Header="Price"
DataType="GridColumnDataType.Number"
HasSummary="true"
Editable="true">
</IgbColumn>
<IgbColumn
Field="Delivered"
DataType="GridColumnDataType.Boolean">
</IgbColumn>
<IgbColumn
Field="OrderDate"
Header="Order Date"
DataType="GridColumnDataType.Date">
</IgbColumn>
</IgbTreeGrid>
</div>
</div>
@code {
private Action BindElements { get; set; }
protected override async Task OnAfterRenderAsync(bool firstRender)
{
var propertyEditorPanel1 = this.propertyEditorPanel1;
var summaryCalculationModeEditor = this.summaryCalculationModeEditor;
var summaryPositionEditor = this.summaryPositionEditor;
var showSummaryOnCollapseEditor = this.showSummaryOnCollapseEditor;
var treeGrid = this.treeGrid;
this.BindElements = () => {
propertyEditorPanel1.Target = this.treeGrid;
};
this.BindElements();
}
private IgbPropertyEditorPanel propertyEditorPanel1;
private IgbPropertyEditorPropertyDescription summaryCalculationModeEditor;
private IgbPropertyEditorPropertyDescription summaryPositionEditor;
private IgbPropertyEditorPropertyDescription showSummaryOnCollapseEditor;
private IgbTreeGrid treeGrid;
private OrdersTreeData _ordersTreeData = null;
public OrdersTreeData OrdersTreeData
{
get
{
if (_ordersTreeData == null)
{
_ordersTreeData = new OrdersTreeData();
}
return _ordersTreeData;
}
}
}
razor
igRegisterScript("WebTreeGridChangeSummaryCalculationMode", (sender, evtArgs) => {
var treeGrid = document.getElementById("treeGrid");
treeGrid.summaryCalculationMode = evtArgs.newValue;
}, false);
igRegisterScript("WebTreeGridChangeSummaryPosition", (sender, evtArgs) => {
var treeGrid = document.getElementById("treeGrid");
treeGrid.summaryPosition = evtArgs.newValue;
}, false);
js/*
CSS styles are loaded from the shared CSS file located at:
https://static.infragistics.com/xplatform/css/samples/
*/
css
Keyboard Navigation
The summary rows can be navigated with the following keyboard interactions:
- UP - navigates one cell up.
- DOWN - navigates one cell down.
- LEFT - navigates one cell left.
- RIGHT - navigates one cell right.
- CTRL + LEFT or HOME - navigates to the leftmost cell.
- CTRL + RIGHT or END - navigates to the rightmost cell.
Styling
In addition to the predefined themes, the grid could be further customized by setting some of the available CSS properties. In case you would like to change some of the colors, you need to set a class for the grid first:
<IgbTreeGrid class="grid"></IgbTreeGrid>
razor
Then set the related CSS properties for that class:
.grid {
--ig-grid-summary-background-color:#e0f3ff;
--ig-grid-summary-focus-background-color: rgba( #94d1f7, .3 );
--ig-grid-summary-label-color: rgb(228, 27, 117);
--ig-grid-summary-result-color: black;
}
css
Demo
using System;
using System.Net.Http;
using System.Collections.Generic;
using System.Threading.Tasks;
using System.Text;
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using IgniteUI.Blazor.Controls; // for registering Ignite UI modules
namespace Infragistics.Samples
{
public class Program
{
public static async Task Main(string[] args)
{
var builder = WebAssemblyHostBuilder.CreateDefault(args);
builder.RootComponents.Add<App>("app");
builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) });
// registering Ignite UI modules
builder.Services.AddIgniteUIBlazor(
typeof(IgbInputModule),
typeof(IgbTreeGridModule)
);
await builder.Build().RunAsync();
}
}
}
csusing System;
using System.Collections.Generic;
public class OrdersTreeDataItem
{
public double ID { get; set; }
public double ParentID { get; set; }
public string Name { get; set; }
public string Category { get; set; }
public string OrderDate { get; set; }
public double Units { get; set; }
public double UnitPrice { get; set; }
public double Price { get; set; }
public bool Delivered { get; set; }
}
public class OrdersTreeData
: List<OrdersTreeDataItem>
{
public OrdersTreeData()
{
this.Add(new OrdersTreeDataItem()
{
ID = 1,
ParentID = -1,
Name = @"Order 1",
Category = @"",
OrderDate = @"2010-02-17",
Units = 1844,
UnitPrice = 3.73,
Price = 6884.38,
Delivered = true
});
this.Add(new OrdersTreeDataItem()
{
ID = 101,
ParentID = 1,
Name = @"Chocolate Chip Cookies",
Category = @"Cookies",
OrderDate = @"2010-02-17",
Units = 834,
UnitPrice = 3.59,
Price = 2994.06,
Delivered = true
});
this.Add(new OrdersTreeDataItem()
{
ID = 102,
ParentID = 1,
Name = @"Red Apples",
Category = @"Fruit",
OrderDate = @"2010-02-17",
Units = 371,
UnitPrice = 3.66,
Price = 1357.86,
Delivered = true
});
this.Add(new OrdersTreeDataItem()
{
ID = 103,
ParentID = 1,
Name = @"Butter",
Category = @"Diary",
OrderDate = @"2010-02-17",
Units = 260,
UnitPrice = 3.45,
Price = 897,
Delivered = true
});
this.Add(new OrdersTreeDataItem()
{
ID = 104,
ParentID = 1,
Name = @"Potato Chips",
Category = @"Snack",
OrderDate = @"2010-02-17",
Units = 118,
UnitPrice = 1.96,
Price = 231.28,
Delivered = true
});
this.Add(new OrdersTreeDataItem()
{
ID = 105,
ParentID = 1,
Name = @"Orange Juice",
Category = @"Beverages",
OrderDate = @"2010-02-17",
Units = 261,
UnitPrice = 5.38,
Price = 1404.18,
Delivered = true
});
this.Add(new OrdersTreeDataItem()
{
ID = 2,
ParentID = -1,
Name = @"Order 2",
Category = @"",
OrderDate = @"2022-05-27",
Units = 1831,
UnitPrice = 8.23,
Price = 15062.77,
Delivered = false
});
this.Add(new OrdersTreeDataItem()
{
ID = 201,
ParentID = 2,
Name = @"Frozen Shrimps",
Category = @"Seafood",
OrderDate = @"2022-05-27",
Units = 120,
UnitPrice = 20.45,
Price = 2454,
Delivered = false
});
this.Add(new OrdersTreeDataItem()
{
ID = 202,
ParentID = 2,
Name = @"Ice Tea",
Category = @"Beverages",
OrderDate = @"2022-05-27",
Units = 840,
UnitPrice = 7,
Price = 5880,
Delivered = false
});
this.Add(new OrdersTreeDataItem()
{
ID = 203,
ParentID = 2,
Name = @"Fresh Cheese",
Category = @"Diary",
OrderDate = @"2022-05-27",
Units = 267,
UnitPrice = 16.55,
Price = 4418.85,
Delivered = false
});
this.Add(new OrdersTreeDataItem()
{
ID = 204,
ParentID = 2,
Name = @"Carrots",
Category = @"Vegetables",
OrderDate = @"2022-05-27",
Units = 360,
UnitPrice = 2.77,
Price = 997.2,
Delivered = false
});
this.Add(new OrdersTreeDataItem()
{
ID = 205,
ParentID = 2,
Name = @"Apple Juice",
Category = @"Beverages",
OrderDate = @"2022-05-27",
Units = 244,
UnitPrice = 5.38,
Price = 1312.72,
Delivered = false
});
this.Add(new OrdersTreeDataItem()
{
ID = 3,
ParentID = -1,
Name = @"Order 3",
Category = @"",
OrderDate = @"2022-08-04",
Units = 1972,
UnitPrice = 3.47,
Price = 6849.18,
Delivered = true
});
this.Add(new OrdersTreeDataItem()
{
ID = 301,
ParentID = 3,
Name = @"Skimmed Milk 1L",
Category = @"Diary",
OrderDate = @"2022-08-04",
Units = 1028,
UnitPrice = 3.56,
Price = 3659.68,
Delivered = true
});
this.Add(new OrdersTreeDataItem()
{
ID = 302,
ParentID = 3,
Name = @"Bananas 5 Pack",
Category = @"Fruit",
OrderDate = @"2022-08-04",
Units = 370,
UnitPrice = 6.36,
Price = 2353.2,
Delivered = true
});
this.Add(new OrdersTreeDataItem()
{
ID = 303,
ParentID = 3,
Name = @"Cauliflower",
Category = @"Vegetables",
OrderDate = @"2022-08-04",
Units = 283,
UnitPrice = 0.95,
Price = 268.85,
Delivered = true
});
this.Add(new OrdersTreeDataItem()
{
ID = 304,
ParentID = 3,
Name = @"White Chocolate Cookies",
Category = @"Cookies",
OrderDate = @"2022-08-04",
Units = 291,
UnitPrice = 1.95,
Price = 567.45,
Delivered = true
});
this.Add(new OrdersTreeDataItem()
{
ID = 4,
ParentID = -1,
Name = @"Order 4",
Category = @"",
OrderDate = @"2023-01-04",
Units = 1065,
UnitPrice = 5.56,
Price = 5923.5,
Delivered = true
});
this.Add(new OrdersTreeDataItem()
{
ID = 401,
ParentID = 4,
Name = @"Mini Milk Chocolate Cookie Bites",
Category = @"Cookies",
OrderDate = @"2023-01-04",
Units = 68,
UnitPrice = 2.25,
Price = 153,
Delivered = true
});
this.Add(new OrdersTreeDataItem()
{
ID = 402,
ParentID = 4,
Name = @"Wild Salmon Fillets",
Category = @"Seafood",
OrderDate = @"2023-01-04",
Units = 320,
UnitPrice = 16.15,
Price = 5168,
Delivered = true
});
this.Add(new OrdersTreeDataItem()
{
ID = 403,
ParentID = 4,
Name = @"Diet Lemonade",
Category = @"Beverages",
OrderDate = @"2023-01-04",
Units = 437,
UnitPrice = 0.5,
Price = 218.5,
Delivered = true
});
this.Add(new OrdersTreeDataItem()
{
ID = 404,
ParentID = 4,
Name = @"Potatoes",
Category = @"Vegetables",
OrderDate = @"2023-01-04",
Units = 240,
UnitPrice = 1.6,
Price = 384,
Delivered = true
});
}
}
cs
@using IgniteUI.Blazor.Controls
@inject IJSRuntime JS
<style>
/*
CSS styles are loaded from the shared CSS file located at:
https://static.infragistics.com/xplatform/css/samples/
*/
#treeGrid {
--ig-grid-summary-background-color:#e0f3ff;
--ig-grid-summary-focus-background-color: rgba( #94d1f7, .3 );
--ig-grid-summary-label-color: rgb(228, 27, 117);
--ig-grid-summary-result-color: black;
}
</style>
<div class="container vertical ig-typography">
<div class="container vertical fill">
<IgbTreeGrid
AutoGenerate="false"
Data="OrdersTreeData"
Name="treeGrid"
@ref="treeGrid"
Id="treeGrid"
PrimaryKey="ID"
ForeignKey="ParentID">
<IgbColumn
Field="ID"
Header="Order ID">
</IgbColumn>
<IgbColumn
Field="Name"
Header="Order Product"
HasSummary="true"
HeaderTemplateScript="WebTreeGridSummariesHeaderTemplate"
Name="column1"
@ref="column1">
</IgbColumn>
<IgbColumn
Field="Category"
Header="Category"
HasSummary="true"
HeaderTemplateScript="WebTreeGridSummariesHeaderTemplate"
Name="column2"
@ref="column2">
</IgbColumn>
<IgbColumn
Field="Units"
Header="Units"
DataType="GridColumnDataType.Number"
HasSummary="true"
Editable="true"
HeaderTemplateScript="WebTreeGridSummariesHeaderTemplate"
Name="column3"
@ref="column3">
</IgbColumn>
<IgbColumn
Field="UnitPrice"
Header="Unit Price"
DataType="GridColumnDataType.Number"
HasSummary="true"
Editable="true"
HeaderTemplateScript="WebTreeGridSummariesHeaderTemplate"
Name="column4"
@ref="column4">
</IgbColumn>
<IgbColumn
Field="Price"
Header="Price"
DataType="GridColumnDataType.Number"
HasSummary="true"
Editable="true"
HeaderTemplateScript="WebTreeGridSummariesHeaderTemplate"
Name="column5"
@ref="column5">
</IgbColumn>
<IgbColumn
Field="Delivered"
Header="Delivered"
DataType="GridColumnDataType.Boolean"
HasSummary="true"
HeaderTemplateScript="WebTreeGridSummariesHeaderTemplate"
Name="column6"
@ref="column6">
</IgbColumn>
<IgbColumn
Field="OrderDate"
Header="Order Date"
DataType="GridColumnDataType.Date"
HasSummary="true"
HeaderTemplateScript="WebTreeGridSummariesHeaderTemplate"
Name="column7"
@ref="column7">
</IgbColumn>
</IgbTreeGrid>
</div>
</div>
@code {
protected override async Task OnAfterRenderAsync(bool firstRender)
{
var treeGrid = this.treeGrid;
var column1 = this.column1;
var column2 = this.column2;
var column3 = this.column3;
var column4 = this.column4;
var column5 = this.column5;
var column6 = this.column6;
var column7 = this.column7;
}
private IgbTreeGrid treeGrid;
private IgbColumn column1;
private IgbColumn column2;
private IgbColumn column3;
private IgbColumn column4;
private IgbColumn column5;
private IgbColumn column6;
private IgbColumn column7;
private OrdersTreeData _ordersTreeData = null;
public OrdersTreeData OrdersTreeData
{
get
{
if (_ordersTreeData == null)
{
_ordersTreeData = new OrdersTreeData();
}
return _ordersTreeData;
}
}
}
razor
igRegisterScript("WebTreeGridSummariesHeaderTemplate", (ctx) => {
var html = window.igTemplating.html;
window.toggleSummary = function toggleSummary(column) {
column.hasSummary = !column.hasSummary;
}
return html`<div>
<span style="float:left">${ctx.column.field}</span>
<span style="float:right; color:${ctx.column.hasSummary ? '#e41c77' : ''}" @pointerdown=${() => toggleSummary(ctx.column)}>∑</span>
</div>`;
}, false);
js/*
CSS styles are loaded from the shared CSS file located at:
https://static.infragistics.com/xplatform/css/samples/
*/
#treeGrid {
--ig-grid-summary-background-color:#e0f3ff;
--ig-grid-summary-focus-background-color: rgba( #94d1f7, .3 );
--ig-grid-summary-label-color: rgb(228, 27, 117);
--ig-grid-summary-result-color: black;
}
css
API References
SummaryOperand
NumberSummaryOperand
DateSummaryOperand
IgbColumnGroup
IgbColumn
Additional Resources
Our community is active and always welcoming to new ideas.