Web Components Tree Grid Summaries
Web Components Tree Grid의 Ignite UI for Web Components는 그룹 푸터로 열 단위로 작동합니다. Web Components IgcTreeGrid 요약은 사용자가 열 내 데이터 유형에 따라 또는 IgcTreeGridComponent
에서 사용자 정의 템플릿을 구현하여 사전 정의된 기본 요약 항목 집합이 있는 별도의 컨테이너에서 열 정보를 볼 수 있도록 하는 강력한 기능입니다.
Web Components 트리 그리드 요약 개요 예제
export class OrdersTreeDataItem {
public constructor(init: Partial<OrdersTreeDataItem>) {
Object.assign(this, init);
}
public ID: number;
public ParentID: number;
public Name: string;
public Category: string;
public OrderDate: string;
public Units: number;
public UnitPrice: number;
public Price: number;
public Delivered: boolean;
}
export class OrdersTreeData extends Array<OrdersTreeDataItem> {
public constructor(items: Array<OrdersTreeDataItem> | number = -1) {
if (Array.isArray(items)) {
super(...items);
} else {
const newItems = [
new OrdersTreeDataItem(
{
ID: 1,
ParentID: -1,
Name: `Order 1`,
Category: ``,
OrderDate: `2010-02-17`,
Units: 1844,
UnitPrice: 3.73,
Price: 6884.38,
Delivered: true
}),
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
}),
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
}),
new OrdersTreeDataItem(
{
ID: 103,
ParentID: 1,
Name: `Butter`,
Category: `Diary`,
OrderDate: `2010-02-17`,
Units: 260,
UnitPrice: 3.45,
Price: 897,
Delivered: true
}),
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
}),
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
}),
new OrdersTreeDataItem(
{
ID: 2,
ParentID: -1,
Name: `Order 2`,
Category: ``,
OrderDate: `2022-05-27`,
Units: 1831,
UnitPrice: 8.23,
Price: 15062.77,
Delivered: false
}),
new OrdersTreeDataItem(
{
ID: 201,
ParentID: 2,
Name: `Frozen Shrimps`,
Category: `Seafood`,
OrderDate: `2022-05-27`,
Units: 120,
UnitPrice: 20.45,
Price: 2454,
Delivered: false
}),
new OrdersTreeDataItem(
{
ID: 202,
ParentID: 2,
Name: `Ice Tea`,
Category: `Beverages`,
OrderDate: `2022-05-27`,
Units: 840,
UnitPrice: 7,
Price: 5880,
Delivered: false
}),
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
}),
new OrdersTreeDataItem(
{
ID: 204,
ParentID: 2,
Name: `Carrots`,
Category: `Vegetables`,
OrderDate: `2022-05-27`,
Units: 360,
UnitPrice: 2.77,
Price: 997.2,
Delivered: false
}),
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
}),
new OrdersTreeDataItem(
{
ID: 3,
ParentID: -1,
Name: `Order 3`,
Category: ``,
OrderDate: `2022-08-04`,
Units: 1972,
UnitPrice: 3.47,
Price: 6849.18,
Delivered: true
}),
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
}),
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
}),
new OrdersTreeDataItem(
{
ID: 303,
ParentID: 3,
Name: `Cauliflower`,
Category: `Vegetables`,
OrderDate: `2022-08-04`,
Units: 283,
UnitPrice: 0.95,
Price: 268.85,
Delivered: true
}),
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
}),
new OrdersTreeDataItem(
{
ID: 4,
ParentID: -1,
Name: `Order 4`,
Category: ``,
OrderDate: `2023-01-04`,
Units: 1065,
UnitPrice: 5.56,
Price: 5923.5,
Delivered: true
}),
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
}),
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
}),
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
}),
new OrdersTreeDataItem(
{
ID: 404,
ParentID: 4,
Name: `Potatoes`,
Category: `Vegetables`,
OrderDate: `2023-01-04`,
Units: 240,
UnitPrice: 1.6,
Price: 384,
Delivered: true
}),
];
super(...newItems.slice(0));
}
}
}
tsimport 'igniteui-webcomponents-grids/grids/combined';
import { ComponentRenderer, WebTreeGridDescriptionModule } from 'igniteui-webcomponents-core';
import { IgcTreeGridComponent, IgcColumnComponent } from 'igniteui-webcomponents-grids/grids';
import { OrdersTreeDataItem, OrdersTreeData } from './OrdersTreeData';
import { IgcColumnTemplateContext } from 'igniteui-webcomponents-grids/grids';
import { html, nothing } from 'lit-html';
import "igniteui-webcomponents-grids/grids/themes/light/bootstrap.css";
import "./index.css";
export class Sample {
private treeGrid: IgcTreeGridComponent
private column1: IgcColumnComponent
private column2: IgcColumnComponent
private column3: IgcColumnComponent
private column4: IgcColumnComponent
private column5: IgcColumnComponent
private column6: IgcColumnComponent
private _bind: () => void;
constructor() {
var treeGrid = this.treeGrid = document.getElementById('treeGrid') as IgcTreeGridComponent;
var column1 = this.column1 = document.getElementById('column1') as IgcColumnComponent;
var column2 = this.column2 = document.getElementById('column2') as IgcColumnComponent;
var column3 = this.column3 = document.getElementById('column3') as IgcColumnComponent;
var column4 = this.column4 = document.getElementById('column4') as IgcColumnComponent;
var column5 = this.column5 = document.getElementById('column5') as IgcColumnComponent;
var column6 = this.column6 = document.getElementById('column6') as IgcColumnComponent;
this._bind = () => {
treeGrid.data = this.ordersTreeData;
column1.headerTemplate = this.webTreeGridSummariesHeaderTemplate;
column2.headerTemplate = this.webTreeGridSummariesHeaderTemplate;
column3.headerTemplate = this.webTreeGridSummariesHeaderTemplate;
column4.headerTemplate = this.webTreeGridSummariesHeaderTemplate;
column5.headerTemplate = this.webTreeGridSummariesHeaderTemplate;
column6.headerTemplate = this.webTreeGridSummariesHeaderTemplate;
}
this._bind();
}
private _ordersTreeData: OrdersTreeData = null;
public get ordersTreeData(): OrdersTreeData {
if (this._ordersTreeData == null)
{
this._ordersTreeData = new OrdersTreeData();
}
return this._ordersTreeData;
}
private _componentRenderer: ComponentRenderer = null;
public get renderer(): ComponentRenderer {
if (this._componentRenderer == null) {
this._componentRenderer = new ComponentRenderer();
var context = this._componentRenderer.context;
WebTreeGridDescriptionModule.register(context);
}
return this._componentRenderer;
}
public webTreeGridSummariesHeaderTemplate = (ctx: IgcColumnTemplateContext) => {
const column = (ctx as any).column;
return html`<div>
<span style="float:left">${column.field}</span>
<span style="float:right; color: ${column.hasSummary ? '#e41c77' : ''}" @pointerdown=${(e: any) => this.toggleSummary(column)}>∑</span>
</div>`;
};
public toggleSummary(field: IgcColumnComponent) {
if (field) {
field.hasSummary = !field.hasSummary;
}
}
}
new Sample();
ts<!DOCTYPE html>
<html>
<head>
<title>Sample | Ignite UI | Web Components | infragistics</title>
<meta charset="UTF-8" />
<link rel="shortcut icon" href="https://static.infragistics.com/xplatform/images/browsers/wc.png" >
<link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons" />
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Kanit&display=swap" />
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Titillium Web" />
<link rel="stylesheet" href="https://static.infragistics.com/xplatform/css/samples/shared.v8.css" />
<link rel="stylesheet" href="/src/index.css" type="text/css" />
</head>
<body>
<div id="root">
<div class="container sample ig-typography">
<div class="container fill">
<igc-tree-grid
auto-generate="false"
name="treeGrid"
id="treeGrid"
id="treeGrid"
primary-key="ID"
foreign-key="ParentID">
<igc-column
field="ID"
header="Order ID">
</igc-column>
<igc-column
field="Name"
header="Order Product"
has-summary="true"
name="column1"
id="column1">
</igc-column>
<igc-column
field="Units"
header="Units"
data-type="number"
has-summary="true"
editable="true"
name="column2"
id="column2">
</igc-column>
<igc-column
field="UnitPrice"
header="Unit Price"
data-type="number"
has-summary="true"
editable="true"
name="column3"
id="column3">
</igc-column>
<igc-column
field="Price"
header="Price"
data-type="number"
has-summary="true"
editable="true"
name="column4"
id="column4">
</igc-column>
<igc-column
field="OrderDate"
header="Order Date"
data-type="date"
has-summary="true"
name="column5"
id="column5">
</igc-column>
<igc-column
field="Delivered"
header="Delivered"
data-type="boolean"
has-summary="true"
name="column6"
id="column6">
</igc-column>
</igc-tree-grid>
</div>
</div>
</div>
<!-- This script is needed only for parcel and it will be excluded for webpack -->
<% if (false) { %><script src="src/index.ts"></script><% } %>
</body>
</html>
html/* shared styles are loaded from: */
/* https://static.infragistics.com/xplatform/css/samples */
css
열 요약은 모든 열 값의 함수입니다. 필터링이 적용되지 않는 한 열 요약은 필터링된 결과 값의 함수입니다.
IgcTreeGridComponent
요약은 Ignite UI for Web Components에서 열 단위로 활성화할 수도 있습니다. 즉, 필요한 열에 대해서만 활성화할 수 있습니다. IgcTreeGridComponent
요약은 열의 데이터 유형에 따라 미리 정의된 기본 요약 세트를 제공하므로 시간을 절약할 수 있습니다.
string
및 boolean
dataType
의 경우 다음 함수를 사용할 수 있습니다.
- 세다
number
, currency
및 percent
데이터 유형의 경우 다음 함수를 사용할 수 있습니다.
- 세다
- 최소
- 맥스
- 평균
- 합집합
date
데이터 유형의 경우 다음 기능을 사용할 수 있습니다.
- 세다
- 가장 빠른
- 최신
사용 가능한 모든 열 데이터 유형은 공식 열 유형 항목에서 찾을 수 있습니다.
IgcTreeGridComponent
요약은 설정을 통해 열별로 사용할 수 있습니다. hasSummary
property 를 참. 또한 각 열에 대한 요약은 열 데이터 형식에 따라 확인된다는 점을 명심해야 합니다. 안에 IgcTreeGridComponent
기본 열 데이터 형식은 string
, 그래서 당신이 원한다면 number
또는 date
특정 요약을 지정해야 합니다. dataType
속성을 number
또는 date
. 요약 값은 그리드에 따라 지역화되어 표시됩니다 locale
및 열 pipeArgs
.
<igc-tree-grid id="grid1" auto-generate="false" height="800px" width="800px">
<igc-column field="ID" header="Order ID">
</igc-column>
<igc-column field="Name" header="Order Product" has-summary="true">
</igc-column>
<igc-column field="Units" header="Units" editable="true" data-type="number" has-summary="true">
</igc-column>
</igc-tree-grid>
html
특정 열 또는 열 목록에 대한 요약을 활성화/비활성화하는 다른 방법은 public method enableSummaries
/ disableSummaries
of를 IgcTreeGridComponent
사용하는 것입니다.
<igc-tree-grid auto-generate="false" name="treeGrid" id="treeGrid" primary-key="ID">
<igx-column field="ID" header="Order ID" width="200px">
</igx-column>
<igx-column field="Name" header="Order Product" width="200px" [hasSummary]="true">
</igx-column>
<igx-column field="Units" width="200px" [editable]="true" [dataType]="'number'" [hasSummary]="true">
</igx-column>
</igc-tree-grid>
<button id="enableBtn">Enable Summary</button>
<button id="disableBtn">Disable Summary </button>
html
constructor() {
var treeGrid = this.treeGrid = document.getElementById('treeGrid') as IgcTreeGrid;
var enableBtn = this.enableBtn = document.getElementById('enableBtn') as HTMLButtonElement;
var disableBtn = this.disableBtn = document.getElementById('disableBtn') as HTMLButtonElement;
treeGrid.data = this.data;
enableBtn.addEventListener("click", this.enableSummary);
disableBtn.addEventListener("click", this.disableSummary);
}
ts
public enableSummary() {
this.treeGrid.enableSummaries([
{fieldName: 'Name'},
{fieldName: 'Units'}
]);
}
public disableSummary() {
this.treeGrid.disableSummaries(['Units']);
}
typescript
사용자 정의 트리 그리드 요약
이러한 기능이 요구 사항을 충족하지 못하는 경우 특정 열에 대한 사용자 정의 요약을 제공할 수 있습니다.
이를 달성하려면 열 데이터 유형 및 필요에 따라 기본 클래스 IgcSummaryOperand
, IgcNumberSummaryOperand
또는 IgcDateSummaryOperand
중 하나를 재정의해야 합니다. 이 방법으로 기존 기능을 재정의하거나 새 기능을 추가할 수 있습니다. IgcSummaryOperand
클래스는 count
메소드에 대해서만 기본 구현을 제공합니다. IgcNumberSummaryOperand
IgcSummaryOperand
확장하고 Min
, Max
, Sum
및 Average
에 대한 구현을 제공합니다. IgcDateSummaryOperand
IgcSummaryOperand
확장하고 추가로 Earliest
및 Latest
제공합니다.
import { IgcSummaryResult, IgcSummaryOperand, IgcNumberSummaryOperand, IgcDateSummaryOperand } from 'igniteui-webcomponents-grids';
class MySummary extends IgcNumberSummaryOperand {
constructor() {
super();
}
operate(data?: any[]): IgcSummaryResult[] {
const result = super.operate(data);
result.push({
key: 'test',
label: 'Test',
summaryResult: data.filter(rec => rec > 10 && rec < 30).length
});
return result;
}
}
typescript
예제에서 볼 수 있듯이 기본 클래스는 operate
메서드를 노출하므로 모든 기본 요약을 가져오고 결과를 수정하거나 완전히 새로운 요약 결과를 계산하도록 선택할 수 있습니다.
이 메소드는 IgcSummaryResult
목록을 반환합니다.
interface IgcSummaryResult {
key: string;
label: string;
summaryResult: any;
}
typescript
요약을 계산하기 위해 선택적 매개변수를 사용합니다. 아래의 모든 데이터 섹션에 액세스하는 사용자 정의 요약을 참조하세요.
요약 행 높이를 올바르게 계산하려면 트리 그리드에 데이터가 비어 있는 경우에도 항상 적절한 길이의 IgcSummaryResult 배열을 반환하는 작업 메서드가 필요합니다.
이제 열 title
에 사용자 지정 요약을 추가해 보겠습니다. 우리는 Summaries의 속성을 아래에서 만든 클래스로 설정하여 이를 달성할 것입니다.
<igc-tree-grid auto-generate="false" name="treeGrid" id="treeGrid" primary-key="ID">
<igc-column field="Name" data-type="string"></igc-column>
<igc-column field="Age" data-type="number"></igc-column>
<igc-column field="Title" data-type="string" has-summary="true" id="column1"></igc-column>
</igc-tree-grid>
html
constructor() {
var treeGrid = this.treeGrid = document.getElementById('treeGrid') as IgcTreeGrid;
var column1 = this.column1 = document.getElementById('column1') as IgcColumnComponent;
treeGrid.data = this.data;
column1.summaries = this.mySummary;
}
ts
export class TreeGridComponent implements OnInit {
mySummary = MySummary;
}
typescript
모든 데이터에 액세스하는 사용자 정의 요약
이제 사용자 정의 열 요약 내의 모든 트리 그리드 데이터에 액세스할 수 있습니다. SummaryOperand operate
메서드에는 두 개의 추가 선택적 매개 변수가 도입되었습니다. 아래 코드 조각에서 볼 수 있듯이 operate 메서드에는 다음 세 가지 매개 변수가 있습니다.
- columnData - 현재 열의 값만 포함하는 배열을 제공합니다.
- allGridData - 전체 그리드 데이터 소스를 제공합니다.
- fieldName - 현재 열 필드
class MySummary extends IgcNumberSummaryOperand {
constructor() {
super();
}
operate(columnData: any[], allGridData = [], fieldName?): IgcSummaryResult[] {
const result = super.operate(allData.map(r => r[fieldName]));
result.push({ key: 'totalOnPTO', label: 'Employees On PTO', summaryResult: this.count(allData.filter((rec) => rec['OnPTO']).map(r => r[fieldName])) });
return result;
}
}
typescript
export class EmployeesFlatDataItem {
public constructor(init: Partial<EmployeesFlatDataItem>) {
Object.assign(this, init);
}
public Age: number;
public HireDate: string;
public ID: number;
public Name: string;
public Phone: string;
public OnPTO: boolean;
public ParentID: number;
public Title: string;
}
export class EmployeesFlatData extends Array<EmployeesFlatDataItem> {
public constructor(items: Array<EmployeesFlatDataItem> | number = -1) {
if (Array.isArray(items)) {
super(...items);
} else {
const newItems = [
new EmployeesFlatDataItem(
{
Age: 55,
HireDate: `2008-03-20`,
ID: 1,
Name: `Johnathan Winchester`,
Phone: `0251-031259`,
OnPTO: false,
ParentID: -1,
Title: `Development Manager`
}),
new EmployeesFlatDataItem(
{
Age: 42,
HireDate: `2014-01-22`,
ID: 4,
Name: `Ana Sanders`,
Phone: `(21) 555-0091`,
OnPTO: true,
ParentID: -1,
Title: `CEO`
}),
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`
}),
new EmployeesFlatDataItem(
{
Age: 61,
HireDate: `2010-01-01`,
ID: 10,
Name: `Yang Wang`,
Phone: `(21) 555-0091`,
OnPTO: false,
ParentID: -1,
Title: `Localization Manager`
}),
new EmployeesFlatDataItem(
{
Age: 43,
HireDate: `2011-06-03`,
ID: 3,
Name: `Michael Burke`,
Phone: `0452-076545`,
OnPTO: true,
ParentID: 1,
Title: `Senior Software Developer`
}),
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`
}),
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`
}),
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`
}),
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`
}),
new EmployeesFlatDataItem(
{
Age: 44,
HireDate: `2014-04-04`,
ID: 14,
Name: `Laurence Johnson`,
Phone: `981-443655`,
OnPTO: false,
ParentID: 4,
Title: `Director`
}),
new EmployeesFlatDataItem(
{
Age: 25,
HireDate: `2017-11-09`,
ID: 5,
Name: `Elizabeth Richards`,
Phone: `(2) 283-2951`,
OnPTO: true,
ParentID: 4,
Title: `Vice President`
}),
new EmployeesFlatDataItem(
{
Age: 39,
HireDate: `2010-03-22`,
ID: 13,
Name: `Trevor Ashworth`,
Phone: `981-443655`,
OnPTO: true,
ParentID: 5,
Title: `Director`
}),
new EmployeesFlatDataItem(
{
Age: 44,
HireDate: `2014-04-04`,
ID: 17,
Name: `Antonio Moreno`,
Phone: `(505) 555-5939`,
OnPTO: false,
ParentID: 18,
Title: `Senior Accountant`
}),
new EmployeesFlatDataItem(
{
Age: 50,
HireDate: `2007-11-18`,
ID: 7,
Name: `Pedro Rodriguez`,
Phone: `035-640230`,
OnPTO: false,
ParentID: 10,
Title: `Senior Localization Developer`
}),
new EmployeesFlatDataItem(
{
Age: 27,
HireDate: `2016-02-19`,
ID: 8,
Name: `Casey Harper`,
Phone: `0342-023176`,
OnPTO: true,
ParentID: 10,
Title: `Senior Localization`
}),
new EmployeesFlatDataItem(
{
Age: 25,
HireDate: `2017-11-09`,
ID: 15,
Name: `Patricia Simpson`,
Phone: `069-0245984`,
OnPTO: false,
ParentID: 7,
Title: `Localization Intern`
}),
new EmployeesFlatDataItem(
{
Age: 39,
HireDate: `2010-03-22`,
ID: 9,
Name: `Francisco Chang`,
Phone: `(91) 745 6200`,
OnPTO: false,
ParentID: 7,
Title: `Localization Intern`
}),
new EmployeesFlatDataItem(
{
Age: 25,
HireDate: `2018-03-18`,
ID: 16,
Name: `Peter Lewis`,
Phone: `069-0245984`,
OnPTO: true,
ParentID: 7,
Title: `Localization Intern`
}),
];
super(...(newItems.slice(0, items)));
}
}
}
tsimport 'igniteui-webcomponents-grids/grids/combined';
import { ComponentRenderer, WebTreeGridDescriptionModule } from 'igniteui-webcomponents-core';
import { IgcColumnComponent, IgcTreeGridComponent } from 'igniteui-webcomponents-grids/grids';
import { EmployeesFlatDataItem, EmployeesFlatData } from './EmployeesFlatData';
import "igniteui-webcomponents-grids/grids/themes/light/bootstrap.css";
import "./index.css";
class PtoSummary {
count(data: any[]): number {
return data.length;
};
operate(data?: any[], allData: any[] = [], fieldName = ''): any[] {
const result = [] as any[];
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;
}
}
export class Sample {
private treeGrid: IgcTreeGridComponent
private column1: IgcColumnComponent
private _bind: () => void;
constructor() {
var treeGrid = this.treeGrid = document.getElementById('treeGrid') as IgcTreeGridComponent;
var column1 = this.column1 = document.getElementById('column1') as IgcColumnComponent;
this._bind = () => {
treeGrid.data = this.employeesFlatData;
column1.summaries = PtoSummary;
}
this._bind();
}
private _employeesFlatData: EmployeesFlatData = null;
public get employeesFlatData(): EmployeesFlatData {
if (this._employeesFlatData == null)
{
this._employeesFlatData = new EmployeesFlatData();
}
return this._employeesFlatData;
}
private _componentRenderer: ComponentRenderer = null;
public get renderer(): ComponentRenderer {
if (this._componentRenderer == null) {
this._componentRenderer = new ComponentRenderer();
var context = this._componentRenderer.context;
WebTreeGridDescriptionModule.register(context);
}
return this._componentRenderer;
}
}
new Sample();
ts<!DOCTYPE html>
<html>
<head>
<title>Sample | Ignite UI | Web Components | infragistics</title>
<meta charset="UTF-8" />
<link rel="shortcut icon" href="https://static.infragistics.com/xplatform/images/browsers/wc.png" >
<link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons" />
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Kanit&display=swap" />
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Titillium Web" />
<link rel="stylesheet" href="https://static.infragistics.com/xplatform/css/samples/shared.v8.css" />
<link rel="stylesheet" href="/src/index.css" type="text/css" />
</head>
<body>
<div id="root">
<div class="container sample ig-typography">
<div class="container fill">
<igc-tree-grid
class="gridSize"
height="620px"
auto-generate="false"
name="treeGrid"
id="treeGrid"
primary-key="ID"
foreign-key="ParentID">
<igc-column
field="Name"
data-type="string">
</igc-column>
<igc-column
field="Age"
data-type="number">
</igc-column>
<igc-column
field="Title"
data-type="string"
has-summary="true"
name="column1"
id="column1">
</igc-column>
<igc-column
field="HireDate"
data-type="date"
has-summary="true">
</igc-column>
<igc-column
field="OnPTO"
data-type="boolean"
has-summary="true"
editable="true">
</igc-column>
</igc-tree-grid>
</div>
</div>
</div>
<!-- This script is needed only for parcel and it will be excluded for webpack -->
<% if (false) { %><script src="src/index.ts"></script><% } %>
</body>
</html>
html/* shared styles are loaded from: */
/* https://static.infragistics.com/xplatform/css/samples */
.gridSize {
--ig-size: var(--ig-size-small);
}
css
요약 템플릿
summaryTemplate
열 요약 결과를 컨텍스트로 제공하는 열 요약을 대상으로 합니다.
<igc-column id="column" has-summary="true">
</igc-column>
html
constructor() {
var column = this.column = document.getElementById('column') as IgcColumnComponent;
column.summaryTemplate = this.summaryTemplate;
}
public summaryTemplate = (ctx: IgcSummaryTemplateContext) => {
return html`
<span> My custom summary template</span>
<span>${ ctx.implicit[0].label } - ${ ctx.implicit[0].summaryResult }</span>
`;
}
ts
기본 요약이 정의되면 요약 영역의 높이는 요약 수가 가장 많은 열과--ig-size
그리드에 따라 설계에 따라 계산됩니다. summaryRowHeight
input 속성을 사용하여 기본값을 재정의합니다. 인수로 숫자 값이 필요하며 거짓 값을 설정하면 그리드 바닥글의 기본 크기 조정 동작이 트리거됩니다.
export class EmployeesNestedTreeDataItem {
public constructor(init: Partial<EmployeesNestedTreeDataItem>) {
Object.assign(this, init);
}
public Age: number;
public HireDate: string;
public ID: number;
public Name: string;
public Phone: string;
public OnPTO: boolean;
public ParentID: number;
public Title: string;
}
export class EmployeesNestedTreeData extends Array<EmployeesNestedTreeDataItem> {
public constructor(items: Array<EmployeesNestedTreeDataItem> | number = -1) {
if (Array.isArray(items)) {
super(...items);
} else {
const newItems = [
new EmployeesNestedTreeDataItem(
{
Age: 55,
HireDate: `2008-03-20`,
ID: 1,
Name: `Johnathan Winchester`,
Phone: `0251-031259`,
OnPTO: false,
ParentID: -1,
Title: `Development Manager`
}),
new EmployeesNestedTreeDataItem(
{
Age: 42,
HireDate: `2014-01-22`,
ID: 4,
Name: `Ana Sanders`,
Phone: `(21) 555-0091`,
OnPTO: true,
ParentID: -1,
Title: `CEO`
}),
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`
}),
new EmployeesNestedTreeDataItem(
{
Age: 61,
HireDate: `2010-01-01`,
ID: 10,
Name: `Yang Wang`,
Phone: `(21) 555-0091`,
OnPTO: false,
ParentID: -1,
Title: `Localization Manager`
}),
new EmployeesNestedTreeDataItem(
{
Age: 43,
HireDate: `2011-06-03`,
ID: 3,
Name: `Michael Burke`,
Phone: `0452-076545`,
OnPTO: true,
ParentID: 1,
Title: `Senior Software Developer`
}),
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`
}),
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`
}),
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`
}),
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`
}),
new EmployeesNestedTreeDataItem(
{
Age: 44,
HireDate: `2014-04-04`,
ID: 14,
Name: `Laurence Johnson`,
Phone: `981-443655`,
OnPTO: false,
ParentID: 4,
Title: `Director`
}),
new EmployeesNestedTreeDataItem(
{
Age: 25,
HireDate: `2017-11-09`,
ID: 5,
Name: `Elizabeth Richards`,
Phone: `(2) 283-2951`,
OnPTO: true,
ParentID: 4,
Title: `Vice President`
}),
new EmployeesNestedTreeDataItem(
{
Age: 39,
HireDate: `2010-03-22`,
ID: 13,
Name: `Trevor Ashworth`,
Phone: `981-443655`,
OnPTO: true,
ParentID: 5,
Title: `Director`
}),
new EmployeesNestedTreeDataItem(
{
Age: 44,
HireDate: `2014-04-04`,
ID: 17,
Name: `Antonio Moreno`,
Phone: `(505) 555-5939`,
OnPTO: false,
ParentID: 18,
Title: `Senior Accountant`
}),
new EmployeesNestedTreeDataItem(
{
Age: 50,
HireDate: `2007-11-18`,
ID: 7,
Name: `Pedro Rodriguez`,
Phone: `035-640230`,
OnPTO: false,
ParentID: 10,
Title: `Senior Localization Developer`
}),
new EmployeesNestedTreeDataItem(
{
Age: 27,
HireDate: `2016-02-19`,
ID: 8,
Name: `Casey Harper`,
Phone: `0342-023176`,
OnPTO: true,
ParentID: 10,
Title: `Senior Localization`
}),
new EmployeesNestedTreeDataItem(
{
Age: 25,
HireDate: `2017-11-09`,
ID: 15,
Name: `Patricia Simpson`,
Phone: `069-0245984`,
OnPTO: false,
ParentID: 7,
Title: `Localization Intern`
}),
new EmployeesNestedTreeDataItem(
{
Age: 39,
HireDate: `2010-03-22`,
ID: 9,
Name: `Francisco Chang`,
Phone: `(91) 745 6200`,
OnPTO: false,
ParentID: 7,
Title: `Localization Intern`
}),
new EmployeesNestedTreeDataItem(
{
Age: 25,
HireDate: `2018-03-18`,
ID: 16,
Name: `Peter Lewis`,
Phone: `069-0245984`,
OnPTO: true,
ParentID: 7,
Title: `Localization Intern`
}),
];
super(...newItems.slice(0));
}
}
}
tsimport { IgcPropertyEditorPanelModule } from 'igniteui-webcomponents-layouts';
import 'igniteui-webcomponents-grids/grids/combined';
import { ComponentRenderer, PropertyEditorPanelDescriptionModule, WebTreeGridDescriptionModule } from 'igniteui-webcomponents-core';
import { IgcPropertyEditorPanelComponent, IgcPropertyEditorPropertyDescriptionComponent } from 'igniteui-webcomponents-layouts';
import { IgcTreeGridComponent, IgcColumnComponent } from 'igniteui-webcomponents-grids/grids';
import { EmployeesNestedTreeDataItem, EmployeesNestedTreeData } from './EmployeesNestedTreeData';
import { IgcPropertyEditorPropertyDescriptionChangedEventArgs } from 'igniteui-webcomponents-layouts';
import { IgcSummaryResult, IgcSummaryTemplateContext } from 'igniteui-webcomponents-grids/grids';
import { html, nothing } from 'lit-html';
import "igniteui-webcomponents-grids/grids/themes/light/bootstrap.css";
import 'igniteui-webcomponents/themes/light/bootstrap.css';
import { defineAllComponents } from 'igniteui-webcomponents';
import { ModuleManager } from 'igniteui-webcomponents-core';
defineAllComponents();
import "./index.css";
ModuleManager.register(
IgcPropertyEditorPanelModule
);
export class Sample {
private propertyEditorPanel1: IgcPropertyEditorPanelComponent
private summaryRowHeightEditor: IgcPropertyEditorPropertyDescriptionComponent
private toggleSummariesEditor: IgcPropertyEditorPropertyDescriptionComponent
private sizeEditor: IgcPropertyEditorPropertyDescriptionComponent
private treeGrid: IgcTreeGridComponent
private column1: IgcColumnComponent
private _bind: () => void;
constructor() {
var propertyEditorPanel1 = this.propertyEditorPanel1 = document.getElementById('propertyEditorPanel1') as IgcPropertyEditorPanelComponent;
var summaryRowHeightEditor = this.summaryRowHeightEditor = document.getElementById('SummaryRowHeightEditor') as IgcPropertyEditorPropertyDescriptionComponent;
var toggleSummariesEditor = this.toggleSummariesEditor = document.getElementById('ToggleSummariesEditor') as IgcPropertyEditorPropertyDescriptionComponent;
this.webTreeGridHasSummariesChange = this.webTreeGridHasSummariesChange.bind(this);
var sizeEditor = this.sizeEditor = document.getElementById('SizeEditor') as IgcPropertyEditorPropertyDescriptionComponent;
this.webTreeGridSetGridSize = this.webTreeGridSetGridSize.bind(this);
var treeGrid = this.treeGrid = document.getElementById('treeGrid') as IgcTreeGridComponent;
var column1 = this.column1 = document.getElementById('column1') as IgcColumnComponent;
this._bind = () => {
propertyEditorPanel1.componentRenderer = this.renderer;
propertyEditorPanel1.target = this.treeGrid;
toggleSummariesEditor.changed = this.webTreeGridHasSummariesChange;
sizeEditor.changed = this.webTreeGridSetGridSize;
treeGrid.data = this.employeesNestedTreeData;
column1.summaryTemplate = this.webTreeGridSummaryTemplate;
}
this._bind();
}
private _employeesNestedTreeData: EmployeesNestedTreeData = null;
public get employeesNestedTreeData(): EmployeesNestedTreeData {
if (this._employeesNestedTreeData == null)
{
this._employeesNestedTreeData = new EmployeesNestedTreeData();
}
return this._employeesNestedTreeData;
}
private _componentRenderer: ComponentRenderer = null;
public get renderer(): ComponentRenderer {
if (this._componentRenderer == null) {
this._componentRenderer = new ComponentRenderer();
var context = this._componentRenderer.context;
PropertyEditorPanelDescriptionModule.register(context);
WebTreeGridDescriptionModule.register(context);
}
return this._componentRenderer;
}
public webTreeGridHasSummariesChange(sender: any, args: IgcPropertyEditorPropertyDescriptionChangedEventArgs): void {
let newValue = sender.primitiveValue as boolean;
const grid = this.treeGrid;
var column1 = grid.getColumnByName("Age");
var column2 = grid.getColumnByName("Title");
var column3 = grid.getColumnByName("OnPTO");
column1.hasSummary = newValue;
column2.hasSummary = newValue;
column3.hasSummary = newValue;
}
public webTreeGridSetGridSize(sender: any, args: IgcPropertyEditorPropertyDescriptionChangedEventArgs): void {
var newVal = (args.newValue as string).toLowerCase();
var grid = document.getElementById("treeGrid");
grid.style.setProperty('--ig-size', `var(--ig-size-${newVal})`);
}
public webTreeGridSummaryTemplate = (ctx: IgcSummaryTemplateContext) => {
const summaryResults = ctx.implicit as IgcSummaryResult[];
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>`;
}
}
new Sample();
ts<!DOCTYPE html>
<html>
<head>
<title>Sample | Ignite UI | Web Components | infragistics</title>
<meta charset="UTF-8" />
<link rel="shortcut icon" href="https://static.infragistics.com/xplatform/images/browsers/wc.png" >
<link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons" />
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Kanit&display=swap" />
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Titillium Web" />
<link rel="stylesheet" href="https://static.infragistics.com/xplatform/css/samples/shared.v8.css" />
<link rel="stylesheet" href="/src/index.css" type="text/css" />
</head>
<body>
<div id="root">
<div class="container sample ig-typography">
<div class="options vertical">
<igc-property-editor-panel
description-type="WebTreeGrid"
is-horizontal="true"
is-wrapping-enabled="false"
name="propertyEditorPanel1"
id="propertyEditorPanel1">
<igc-property-editor-property-description
property-path="SummaryRowHeight"
label="Summary Row Height"
value-type="Number"
name="SummaryRowHeightEditor"
id="SummaryRowHeightEditor">
</igc-property-editor-property-description>
<igc-property-editor-property-description
label="Toggle Summaries"
value-type="Boolean1"
primitive-value="True"
name="ToggleSummariesEditor"
id="ToggleSummariesEditor">
</igc-property-editor-property-description>
<igc-property-editor-property-description
name="SizeEditor"
id="SizeEditor"
label="Grid Size:"
value-type="EnumValue"
drop-down-names="Small, Medium, Large"
drop-down-values="Small, Medium, Large">
</igc-property-editor-property-description>
</igc-property-editor-panel>
</div>
<div class="container fill">
<igc-tree-grid
auto-generate="false"
name="treeGrid"
id="treeGrid"
id="treeGrid"
primary-key="ID"
foreign-key="ParentID">
<igc-column
field="Name">
</igc-column>
<igc-column
field="Age"
data-type="number"
has-summary="true"
name="column1"
id="column1">
</igc-column>
<igc-column
field="Title"
has-summary="true">
</igc-column>
<igc-column
field="HireDate"
data-type="date">
</igc-column>
<igc-column
field="OnPTO"
data-type="boolean"
editable="true"
has-summary="true">
</igc-column>
</igc-tree-grid>
</div>
</div>
</div>
<!-- This script is needed only for parcel and it will be excluded for webpack -->
<% if (false) { %><script src="src/index.ts"></script><% } %>
</body>
</html>
html/* shared styles are loaded from: */
/* https://static.infragistics.com/xplatform/css/samples */
.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: 14px;
text-transform: uppercase;
min-width: 70px;
justify-self: flex-start;
text-align: left;
color: hsla(var(--ig-secondary-600));
user-select: none;
}
css
장애인 요약
이 disabled-summaries
속성은 Web Components Tree Grid 요약 기능에 대한 열별 정확한 제어를 제공합니다. 이 속성을 사용하면 사용자가 IgcTreeGrid의 각 열에 대해 표시되는 요약을 사용자 지정하여 가장 관련성이 높고 의미 있는 데이터만 표시되도록 할 수 있습니다. 예를 들어, 배열에서 요약 키를 지정하는 것과 같이 ['count', 'min', 'max']
특정 요약 유형을 제외할 수 있습니다.
또한 이 속성은 코드를 통해 런타임에 동적으로 수정할 수 있으므로 IgcTreeGrid의 요약을 애플리케이션 상태 또는 사용자 작업 변경에 맞게 유연하게 조정할 수 있습니다.
다음 예제에서는 속성을 사용하여 disabled-summaries
다른 열에 대한 요약을 관리하고 Web Components 트리 그리드에서 특정 기본 및 사용자 지정 요약 유형을 제외하는 방법을 보여 줍니다.
<!-- Disable default summaries -->
<igc-column
field="UnitPrice"
header="Unit Price"
data-type="number"
has-summary="true"
disabled-summaries="['count', 'sum', 'average']"
>
</igc-column>
<!-- Disable custom summaries -->
<igc-column
field="UnitsInStock"
header="Units In Stock"
data-type="number"
has-summary="true"
summaries="discontinuedSummary"
disabled-summaries="['discontinued', 'totalDiscontinued']"
>
</igc-column>
html
의 UnitPrice
경우, 기본 요약은 , sum
와 average
같고 count
비활성화되어 있으며 다른 요약은 같고 min
max
활성 상태로 유지됩니다.
의 경우 UnitsInStock
, 및 totalDiscontinued
와 같은 discontinued
사용자 지정 요약은 disabled-summaries
속성을 사용하여 제외됩니다.
런타임에 이 속성을 사용하여 disabledSummaries
요약을 동적으로 사용하지 않도록 설정할 수도 있습니다. 예를 들어 프로그래밍 방식으로 특정 열의 속성을 설정하거나 업데이트하여 사용자 작업 또는 응용 프로그램 상태 변경에 따라 표시된 요약을 조정할 수 있습니다.
export class OrdersTreeDataItem {
public constructor(init: Partial<OrdersTreeDataItem>) {
Object.assign(this, init);
}
public ID: number;
public ParentID: number;
public Name: string;
public Category: string;
public OrderDate: string;
public Units: number;
public UnitPrice: number;
public Price: number;
public Delivered: boolean;
}
export class OrdersTreeData extends Array<OrdersTreeDataItem> {
public constructor(items: Array<OrdersTreeDataItem> | number = -1) {
if (Array.isArray(items)) {
super(...items);
} else {
const newItems = [
new OrdersTreeDataItem(
{
ID: 1,
ParentID: -1,
Name: `Order 1`,
Category: ``,
OrderDate: `2010-02-17`,
Units: 1844,
UnitPrice: 3.73,
Price: 6884.38,
Delivered: true
}),
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
}),
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
}),
new OrdersTreeDataItem(
{
ID: 103,
ParentID: 1,
Name: `Butter`,
Category: `Diary`,
OrderDate: `2010-02-17`,
Units: 260,
UnitPrice: 3.45,
Price: 897,
Delivered: true
}),
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
}),
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
}),
new OrdersTreeDataItem(
{
ID: 2,
ParentID: -1,
Name: `Order 2`,
Category: ``,
OrderDate: `2022-05-27`,
Units: 1831,
UnitPrice: 8.23,
Price: 15062.77,
Delivered: false
}),
new OrdersTreeDataItem(
{
ID: 201,
ParentID: 2,
Name: `Frozen Shrimps`,
Category: `Seafood`,
OrderDate: `2022-05-27`,
Units: 120,
UnitPrice: 20.45,
Price: 2454,
Delivered: false
}),
new OrdersTreeDataItem(
{
ID: 202,
ParentID: 2,
Name: `Ice Tea`,
Category: `Beverages`,
OrderDate: `2022-05-27`,
Units: 840,
UnitPrice: 7,
Price: 5880,
Delivered: false
}),
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
}),
new OrdersTreeDataItem(
{
ID: 204,
ParentID: 2,
Name: `Carrots`,
Category: `Vegetables`,
OrderDate: `2022-05-27`,
Units: 360,
UnitPrice: 2.77,
Price: 997.2,
Delivered: false
}),
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
}),
new OrdersTreeDataItem(
{
ID: 3,
ParentID: -1,
Name: `Order 3`,
Category: ``,
OrderDate: `2022-08-04`,
Units: 1972,
UnitPrice: 3.47,
Price: 6849.18,
Delivered: true
}),
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
}),
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
}),
new OrdersTreeDataItem(
{
ID: 303,
ParentID: 3,
Name: `Cauliflower`,
Category: `Vegetables`,
OrderDate: `2022-08-04`,
Units: 283,
UnitPrice: 0.95,
Price: 268.85,
Delivered: true
}),
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
}),
new OrdersTreeDataItem(
{
ID: 4,
ParentID: -1,
Name: `Order 4`,
Category: ``,
OrderDate: `2023-01-04`,
Units: 1065,
UnitPrice: 5.56,
Price: 5923.5,
Delivered: true
}),
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
}),
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
}),
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
}),
new OrdersTreeDataItem(
{
ID: 404,
ParentID: 4,
Name: `Potatoes`,
Category: `Vegetables`,
OrderDate: `2023-01-04`,
Units: 240,
UnitPrice: 1.6,
Price: 384,
Delivered: true
}),
];
super(...newItems.slice(0));
}
}
}
tsimport "igniteui-webcomponents-grids/grids/combined";
import { defineComponents, IgcButtonComponent, IgcDialogComponent, IgcCheckboxComponent } from "igniteui-webcomponents";
import { ComponentRenderer, WebGridDescriptionModule } from "igniteui-webcomponents-core";
import { IgcTreeGridComponent, IgcColumnComponent, IgcSummaryOperand, IgcSummaryResult } from "igniteui-webcomponents-grids/grids";
import { OrdersTreeData } from "./OrdersTreeData";
import "igniteui-webcomponents-grids/grids/themes/light/bootstrap.css";
import "./index.css";
defineComponents(IgcButtonComponent, IgcDialogComponent, IgcCheckboxComponent);
class UnitsSummary extends IgcSummaryOperand {
constructor() {
super();
}
operate(data?: any[], allData: any[] = [], fieldName: string = ""): IgcSummaryResult[] {
const result: IgcSummaryResult[] = [];
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;
}
}
class DeliveredSummary extends IgcSummaryOperand {
constructor() {
super();
}
operate(data: any[] = [], allData: any[] = [], fieldName: string = ""): IgcSummaryResult[] {
const result: IgcSummaryResult[] = [];
result.push({
key: "count",
label: "Count",
summaryResult: allData.length
});
result.push({
key: "true",
label: "True",
summaryResult: allData.filter((item) => item[fieldName] === true).length
});
result.push({
key: "false",
label: "False",
summaryResult: allData.filter((item) => item[fieldName] === false).length
});
return result;
}
}
export class Sample {
private treeGrid: IgcTreeGridComponent;
private dialog: IgcDialogComponent;
private _bind: () => void;
private currentColumn: IgcColumnComponent | null = null;
private summariesContainer: HTMLDivElement | null = null;
private disableAllBtn!: HTMLButtonElement;
private enableAllBtn!: HTMLButtonElement;
constructor() {
this.treeGrid = document.getElementById("treeGrid") as IgcTreeGridComponent;
this.dialog = document.getElementById("dialog") as IgcDialogComponent;
this.dialog.closeOnOutsideClick = true;
this.dialog.keepOpenOnEscape = false;
this.summariesContainer = document.querySelector(".summaries");
if (this.summariesContainer) {
const title = document.createElement("p");
title.classList.add("summaries-title");
title.textContent = "Disable Summaries for Column:";
this.summariesContainer.appendChild(title);
}
this.disableAllBtn = document.getElementById("disableAllBtn") as HTMLButtonElement;
this.enableAllBtn = document.getElementById("enableAllBtn") as HTMLButtonElement;
this.webGridCustomSummary = this.webGridCustomSummary.bind(this);
this.openDialog = this.openDialog.bind(this);
this.toggleSummary = this.toggleSummary.bind(this);
this.disableAllSummaries = this.disableAllSummaries.bind(this);
this.enableAllSummaries = this.enableAllSummaries.bind(this);
this.handleColumnInit = this.handleColumnInit.bind(this);
this.updateCheckboxes = this.updateCheckboxes.bind(this);
this._bind = () => {
this.treeGrid.data = this.ordersTreeData;
this.treeGrid.addEventListener("columnInit", this.handleColumnInit);
document.getElementById("disableAllBtn")!.addEventListener("click", this.disableAllSummaries);
document.getElementById("enableAllBtn")!.addEventListener("click", this.enableAllSummaries);
};
this._bind();
}
private handleColumnInit(event: any) {
this.webGridCustomSummary(event);
const column: IgcColumnComponent = event.detail;
if (!this.summariesContainer) return;
const button = document.createElement("igc-button");
button.classList.add("summary-button");
button.textContent = column.header ? column.header.toString() : column.field;
button.setAttribute("variant", "contained");
button.addEventListener("click", () => this.openDialog(column));
this.summariesContainer.appendChild(button);
}
private _ordersTreeData: OrdersTreeData | undefined;
public get ordersTreeData(): OrdersTreeData {
if (this._ordersTreeData == null) {
this._ordersTreeData = new OrdersTreeData();
}
return this._ordersTreeData;
}
private _componentRenderer: ComponentRenderer | undefined;
public get renderer(): ComponentRenderer {
if (this._componentRenderer == null) {
this._componentRenderer = new ComponentRenderer();
WebGridDescriptionModule.register(this._componentRenderer.context);
}
return this._componentRenderer;
}
public webGridCustomSummary(args: any): void {
if (args.detail.field === "Units") {
args.detail.summaries = UnitsSummary;
}
if (args.detail.field === "Delivered") {
args.detail.summaries = DeliveredSummary;
}
}
private updateCheckboxes() {
if (!this.currentColumn) return;
const dialogItemsContainer = this.dialog.querySelector(".summaries-dialog-items")!;
dialogItemsContainer.innerHTML = "";
let allSummaries: IgcSummaryResult[] = [];
const getSummaryResults = (operand: any): IgcSummaryResult[] => {
if (typeof operand === "function") {
operand = new operand();
}
if (operand instanceof IgcSummaryOperand) {
return operand.operate([], this.treeGrid.data, this.currentColumn!.field);
}
return [];
};
if (!this.currentColumn.summaries) {
const defaultOperand = IgcSummaryOperand;
allSummaries = getSummaryResults(defaultOperand);
} else {
allSummaries = getSummaryResults(this.currentColumn.summaries);
}
let allDisabled = true;
let allEnabled = true;
allSummaries.forEach((summary) => {
const checkbox = document.createElement("igc-checkbox") as IgcCheckboxComponent;
checkbox.classList.add("summaries-dialog-item");
checkbox.textContent = summary.label;
const isDisabled = this.currentColumn!.disabledSummaries?.includes(summary.key);
checkbox.checked = isDisabled;
if (isDisabled) {
allEnabled = false;
} else {
allDisabled = false;
}
checkbox.addEventListener("click", () => this.toggleSummary(summary.key));
dialogItemsContainer.appendChild(checkbox);
});
this.disableAllBtn.disabled = allDisabled;
this.enableAllBtn.disabled = allEnabled;
}
public openDialog(column: IgcColumnComponent) {
this.currentColumn = column;
this.dialog.title = `Disable Summaries for ${column.header || column.field}`;
this.updateCheckboxes();
this.dialog.show();
}
public toggleSummary(summaryKey: string) {
if (!this.currentColumn) return;
if (!this.currentColumn.disabledSummaries) {
this.currentColumn.disabledSummaries = [];
}
if (this.currentColumn.disabledSummaries.includes(summaryKey)) {
this.currentColumn.disabledSummaries = this.currentColumn.disabledSummaries.filter((key: string) => key !== summaryKey);
} else {
this.currentColumn.disabledSummaries = [...this.currentColumn.disabledSummaries, summaryKey];
}
this.updateCheckboxes();
}
public disableAllSummaries() {
if (!this.currentColumn) return;
let allSummaryKeys: string[] = [];
const getSummaryKeys = (operand: any): string[] => {
if (typeof operand === "function") {
operand = new operand();
}
if (operand instanceof IgcSummaryOperand) {
if (this.treeGrid && this.currentColumn) {
return operand.operate([], this.treeGrid.data, this.currentColumn.field).map((s: { key: any; }) => s.key);
}
return [];
}
return [];
};
if (!this.currentColumn.summaries) {
const defaultOperand = IgcSummaryOperand;
allSummaryKeys = getSummaryKeys(defaultOperand);
} else {
allSummaryKeys = getSummaryKeys(this.currentColumn.summaries);
}
this.currentColumn.disabledSummaries = allSummaryKeys;
this.updateCheckboxes();
this.treeGrid.markForCheck();
}
public enableAllSummaries() {
if (!this.currentColumn) return;
this.currentColumn.disabledSummaries = [];
this.updateCheckboxes();
this.treeGrid.markForCheck();
}
}
new Sample();
ts<!DOCTYPE html>
<html>
<head>
<title>Sample | Ignite UI | Web Components | Infragistics</title>
<meta charset="UTF-8" />
<link rel="shortcut icon" href="https://static.infragistics.com/xplatform/images/browsers/wc.png" />
<link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons" />
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Kanit&display=swap" />
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Titillium Web" />
<link rel="stylesheet" href="https://static.infragistics.com/xplatform/css/samples/shared.v8.css" />
<link rel="stylesheet" href="/src/index.css" type="text/css" />
</head>
<body>
<div id="root">
<div class="grid-wrapper">
<div class="summaries">
<igc-dialog id="dialog" title="Disabled Summaries">
<div class="summaries-dialog-items"></div>
<igc-button id="disableAllBtn" slot="footer" variant="flat">Disable All</igc-button>
<igc-button id="enableAllBtn" slot="footer" variant="flat">Enable All</igc-button>
</igc-dialog>
</div>
<igc-tree-grid auto-generate="false" name="treeGrid" id="treeGrid" primary-key="ID" foreign-key="ParentID">
<igc-column field="ID" header="Order ID" has-summary="true"> </igc-column>
<igc-column field="Name" header="Order Product" has-summary="true"> </igc-column>
<igc-column field="Units" header="Units" data-type="number" has-summary="true"> </igc-column>
<igc-column field="UnitPrice" header="Unit Price" data-type="number" has-summary="true"> </igc-column>
<igc-column field="Price" header="Price" data-type="number" has-summary="true"> </igc-column>
<igc-column field="Delivered" header="Delivered" data-type="boolean" has-summary="true"> </igc-column>
<igc-column field="OrderDate" header="Order Date" data-type="date" has-summary="true"> </igc-column>
</igc-tree-grid>
</div>
</div>
<!-- This script is needed only for parcel and it will be excluded for webpack -->
<% if (false) { %>
<script src="src/index.ts"></script>
<% } %>
</body>
</html>
html.grid-wrapper {
margin: 0 auto;
padding: 16px;
height: 87%;
}
.grid-wrapper .summaries {
margin-bottom: 1rem;
display: flex;
align-items: center;
flex-wrap: wrap;
}
.grid-wrapper .summaries-title {
margin: 0 0 1rem 0;
flex-basis: 100%;
font-weight: bold;
}
.grid-wrapper .summary-button {
margin-right: 1rem;
}
igc-dialog {
border: 1px solid #e0e0e0;
border-radius: 8px;
}
igc-dialog::part(title) {
color: #1E6DFE;
}
.summaries-dialog-items {
display: flex;
flex-direction: column;
align-items: flex-start;
}
.summaries-dialog-items .summaries-dialog-item {
display: flex;
align-items: center;
padding: 0 1rem;
}
css
요약 서식 지정
기본적으로 기본 제공 요약 피연산자에 의해 생성된 요약 결과는 그리드 locale
및 pipeArgs
열에 따라 지역화되고 형식이 지정됩니다. 사용자 정의 피연산자를 사용하는 경우 locale
및 pipeArgs
적용되지 않습니다. 요약 결과의 기본 모양을 변경하려면 summaryFormatter
속성을 사용하여 형식을 지정할 수 있습니다.
public dateSummaryFormat(summary: IgcSummaryResult, summaryOperand: IgcSummaryOperand): string {
const result = summary.summaryResult;
if (summaryOperand instanceof IgcDateSummaryOperand && summary.key !== "count" && result !== null && result !== undefined) {
const format = new Intl.DateTimeFormat("en", { year: "numeric" });
return format.format(new Date(result));
}
return result;
}
typescript
<igc-column id="column"></igx-column>
html
constructor() {
var column = this.column = document.getElementById('column') as IgcColumnComponent;
column.summaryFormatter = this.dateSummaryFormat;
}
ts
export class OrdersTreeDataItem {
public constructor(init: Partial<OrdersTreeDataItem>) {
Object.assign(this, init);
}
public ID: number;
public ParentID: number;
public Name: string;
public Category: string;
public OrderDate: string;
public Units: number;
public UnitPrice: number;
public Price: number;
public Delivered: boolean;
}
export class OrdersTreeData extends Array<OrdersTreeDataItem> {
public constructor(items: Array<OrdersTreeDataItem> | number = -1) {
if (Array.isArray(items)) {
super(...items);
} else {
const newItems = [
new OrdersTreeDataItem(
{
ID: 1,
ParentID: -1,
Name: `Order 1`,
Category: ``,
OrderDate: `2010-02-17`,
Units: 1844,
UnitPrice: 3.73,
Price: 6884.38,
Delivered: true
}),
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
}),
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
}),
new OrdersTreeDataItem(
{
ID: 103,
ParentID: 1,
Name: `Butter`,
Category: `Diary`,
OrderDate: `2010-02-17`,
Units: 260,
UnitPrice: 3.45,
Price: 897,
Delivered: true
}),
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
}),
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
}),
new OrdersTreeDataItem(
{
ID: 2,
ParentID: -1,
Name: `Order 2`,
Category: ``,
OrderDate: `2022-05-27`,
Units: 1831,
UnitPrice: 8.23,
Price: 15062.77,
Delivered: false
}),
new OrdersTreeDataItem(
{
ID: 201,
ParentID: 2,
Name: `Frozen Shrimps`,
Category: `Seafood`,
OrderDate: `2022-05-27`,
Units: 120,
UnitPrice: 20.45,
Price: 2454,
Delivered: false
}),
new OrdersTreeDataItem(
{
ID: 202,
ParentID: 2,
Name: `Ice Tea`,
Category: `Beverages`,
OrderDate: `2022-05-27`,
Units: 840,
UnitPrice: 7,
Price: 5880,
Delivered: false
}),
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
}),
new OrdersTreeDataItem(
{
ID: 204,
ParentID: 2,
Name: `Carrots`,
Category: `Vegetables`,
OrderDate: `2022-05-27`,
Units: 360,
UnitPrice: 2.77,
Price: 997.2,
Delivered: false
}),
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
}),
new OrdersTreeDataItem(
{
ID: 3,
ParentID: -1,
Name: `Order 3`,
Category: ``,
OrderDate: `2022-08-04`,
Units: 1972,
UnitPrice: 3.47,
Price: 6849.18,
Delivered: true
}),
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
}),
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
}),
new OrdersTreeDataItem(
{
ID: 303,
ParentID: 3,
Name: `Cauliflower`,
Category: `Vegetables`,
OrderDate: `2022-08-04`,
Units: 283,
UnitPrice: 0.95,
Price: 268.85,
Delivered: true
}),
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
}),
new OrdersTreeDataItem(
{
ID: 4,
ParentID: -1,
Name: `Order 4`,
Category: ``,
OrderDate: `2023-01-04`,
Units: 1065,
UnitPrice: 5.56,
Price: 5923.5,
Delivered: true
}),
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
}),
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
}),
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
}),
new OrdersTreeDataItem(
{
ID: 404,
ParentID: 4,
Name: `Potatoes`,
Category: `Vegetables`,
OrderDate: `2023-01-04`,
Units: 240,
UnitPrice: 1.6,
Price: 384,
Delivered: true
}),
];
super(...newItems.slice(0));
}
}
}
tsimport 'igniteui-webcomponents-grids/grids/combined';
import { ComponentRenderer, WebTreeGridDescriptionModule } from 'igniteui-webcomponents-core';
import { IgcTreeGridComponent, IgcColumnComponent } from 'igniteui-webcomponents-grids/grids';
import { OrdersTreeDataItem, OrdersTreeData } from './OrdersTreeData';
import { IgcSummaryResult, IgcSummaryOperand } from 'igniteui-webcomponents-grids/grids';
import "igniteui-webcomponents-grids/grids/themes/light/bootstrap.css";
import "./index.css";
export class Sample {
private treeGrid: IgcTreeGridComponent
private column1: IgcColumnComponent
private _bind: () => void;
constructor() {
var treeGrid = this.treeGrid = document.getElementById('treeGrid') as IgcTreeGridComponent;
var column1 = this.column1 = document.getElementById('column1') as IgcColumnComponent;
this.webTreeGridSummaryFormatter = this.webTreeGridSummaryFormatter.bind(this);
this._bind = () => {
treeGrid.data = this.ordersTreeData;
column1.summaryFormatter = this.webTreeGridSummaryFormatter;
}
this._bind();
}
private _ordersTreeData: OrdersTreeData = null;
public get ordersTreeData(): OrdersTreeData {
if (this._ordersTreeData == null)
{
this._ordersTreeData = new OrdersTreeData();
}
return this._ordersTreeData;
}
private _componentRenderer: ComponentRenderer = null;
public get renderer(): ComponentRenderer {
if (this._componentRenderer == null) {
this._componentRenderer = new ComponentRenderer();
var context = this._componentRenderer.context;
WebTreeGridDescriptionModule.register(context);
}
return this._componentRenderer;
}
public webTreeGridSummaryFormatter(summary: IgcSummaryResult, summaryOperand: IgcSummaryOperand): string {
const result = summary.summaryResult;
if (summary.key !== "count" && result !== null && result !== undefined) {
const format = new Intl.DateTimeFormat("en", { year: "numeric" });
return format.format(new Date(result));
}
return result;
}
}
new Sample();
ts<!DOCTYPE html>
<html>
<head>
<title>Sample | Ignite UI | Web Components | infragistics</title>
<meta charset="UTF-8" />
<link rel="shortcut icon" href="https://static.infragistics.com/xplatform/images/browsers/wc.png" >
<link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons" />
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Kanit&display=swap" />
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Titillium Web" />
<link rel="stylesheet" href="https://static.infragistics.com/xplatform/css/samples/shared.v8.css" />
<link rel="stylesheet" href="/src/index.css" type="text/css" />
</head>
<body>
<div id="root">
<div class="container sample ig-typography">
<div class="container fill">
<igc-tree-grid
auto-generate="false"
name="treeGrid"
id="treeGrid"
id="treeGrid"
primary-key="ID"
foreign-key="ParentID"
allow-filtering="true"
filter-mode="excelStyleFilter">
<igc-column
field="ID"
header="Order ID"
sortable="true">
</igc-column>
<igc-column
field="Name"
header="Order Product"
sortable="true">
</igc-column>
<igc-column
field="Category"
header="Product Category"
sortable="true">
</igc-column>
<igc-column
field="Units"
header="Units"
data-type="number"
sortable="true">
</igc-column>
<igc-column
field="UnitPrice"
header="Unit Price"
data-type="number"
sortable="true">
</igc-column>
<igc-column
field="Price"
header="Price"
data-type="number"
sortable="true">
</igc-column>
<igc-column
field="OrderDate"
header="Order Date"
data-type="date"
has-summary="true"
sortable="true"
name="column1"
id="column1">
</igc-column>
<igc-column
field="Delivered"
header="Delivered"
data-type="boolean"
sortable="true">
</igc-column>
</igc-tree-grid>
</div>
</div>
</div>
<!-- This script is needed only for parcel and it will be excluded for webpack -->
<% if (false) { %><script src="src/index.ts"></script><% } %>
</body>
</html>
html/* shared styles are loaded from: */
/* https://static.infragistics.com/xplatform/css/samples */
css
하위 요약
루트 노드와 각 중첩된 자식 노드 수준에 대해 별도의 요약을 IgcTreeGridComponent
지원합니다. 표시되는 요약은 속성을 사용하여 구성할 수 있습니다 summaryCalculationMode
. 자식 수준 요약은 summaryPosition
속성을 사용하여 자식 노드 앞이나 뒤에 표시할 수 있습니다. 이러한 두 속성 IgcTreeGridComponent
과 함께 노출 및 showSummaryOnCollapse
속성을 사용하면 참조하는 부모 노드가 축소될 때 요약 행이 계속 표시되는지 여부를 결정할 수 있습니다.
summaryCalculationMode
속성의 사용 가능한 값은 다음과 같습니다.
RootLevelOnly
- 요약은 루트 수준 노드에 대해서만 계산됩니다.ChildLevelsOnly
- 요약은 하위 수준에 대해서만 계산됩니다.RootAndChildLevels
- 루트 및 하위 수준 모두에 대한 요약이 계산됩니다. 이것이 기본값입니다.
summaryPosition
속성의 사용 가능한 값은 다음과 같습니다.
Top
- 요약 행은 하위 행 목록 앞에 나타납니다.Bottom
- 요약 행은 하위 행 목록 뒤에 나타납니다. 이 값은 기본값입니다.
showSummaryOnCollapse
속성은 부울입니다. 기본값은 false로 설정됩니다. 즉, 상위 행이 축소되면 요약 행이 숨겨집니다. 속성이 true로 설정되면 상위 행이 축소될 때 요약 행이 계속 표시됩니다.
summaryPosition 속성은 자식 수준 요약에만 적용됩니다. 루트 수준 요약은 항상 IgcTreeGridComponent의 맨 아래에 고정되어 나타납니다.
export class OrdersTreeDataItem {
public constructor(init: Partial<OrdersTreeDataItem>) {
Object.assign(this, init);
}
public ID: number;
public ParentID: number;
public Name: string;
public Category: string;
public OrderDate: string;
public Units: number;
public UnitPrice: number;
public Price: number;
public Delivered: boolean;
}
export class OrdersTreeData extends Array<OrdersTreeDataItem> {
public constructor(items: Array<OrdersTreeDataItem> | number = -1) {
if (Array.isArray(items)) {
super(...items);
} else {
const newItems = [
new OrdersTreeDataItem(
{
ID: 1,
ParentID: -1,
Name: `Order 1`,
Category: ``,
OrderDate: `2010-02-17`,
Units: 1844,
UnitPrice: 3.73,
Price: 6884.38,
Delivered: true
}),
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
}),
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
}),
new OrdersTreeDataItem(
{
ID: 103,
ParentID: 1,
Name: `Butter`,
Category: `Diary`,
OrderDate: `2010-02-17`,
Units: 260,
UnitPrice: 3.45,
Price: 897,
Delivered: true
}),
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
}),
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
}),
new OrdersTreeDataItem(
{
ID: 2,
ParentID: -1,
Name: `Order 2`,
Category: ``,
OrderDate: `2022-05-27`,
Units: 1831,
UnitPrice: 8.23,
Price: 15062.77,
Delivered: false
}),
new OrdersTreeDataItem(
{
ID: 201,
ParentID: 2,
Name: `Frozen Shrimps`,
Category: `Seafood`,
OrderDate: `2022-05-27`,
Units: 120,
UnitPrice: 20.45,
Price: 2454,
Delivered: false
}),
new OrdersTreeDataItem(
{
ID: 202,
ParentID: 2,
Name: `Ice Tea`,
Category: `Beverages`,
OrderDate: `2022-05-27`,
Units: 840,
UnitPrice: 7,
Price: 5880,
Delivered: false
}),
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
}),
new OrdersTreeDataItem(
{
ID: 204,
ParentID: 2,
Name: `Carrots`,
Category: `Vegetables`,
OrderDate: `2022-05-27`,
Units: 360,
UnitPrice: 2.77,
Price: 997.2,
Delivered: false
}),
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
}),
new OrdersTreeDataItem(
{
ID: 3,
ParentID: -1,
Name: `Order 3`,
Category: ``,
OrderDate: `2022-08-04`,
Units: 1972,
UnitPrice: 3.47,
Price: 6849.18,
Delivered: true
}),
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
}),
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
}),
new OrdersTreeDataItem(
{
ID: 303,
ParentID: 3,
Name: `Cauliflower`,
Category: `Vegetables`,
OrderDate: `2022-08-04`,
Units: 283,
UnitPrice: 0.95,
Price: 268.85,
Delivered: true
}),
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
}),
new OrdersTreeDataItem(
{
ID: 4,
ParentID: -1,
Name: `Order 4`,
Category: ``,
OrderDate: `2023-01-04`,
Units: 1065,
UnitPrice: 5.56,
Price: 5923.5,
Delivered: true
}),
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
}),
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
}),
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
}),
new OrdersTreeDataItem(
{
ID: 404,
ParentID: 4,
Name: `Potatoes`,
Category: `Vegetables`,
OrderDate: `2023-01-04`,
Units: 240,
UnitPrice: 1.6,
Price: 384,
Delivered: true
}),
];
super(...newItems.slice(0));
}
}
}
tsimport { IgcPropertyEditorPanelModule } from 'igniteui-webcomponents-layouts';
import 'igniteui-webcomponents-grids/grids/combined';
import { ComponentRenderer, PropertyEditorPanelDescriptionModule, WebTreeGridDescriptionModule } from 'igniteui-webcomponents-core';
import { IgcPropertyEditorPanelComponent, IgcPropertyEditorPropertyDescriptionComponent } from 'igniteui-webcomponents-layouts';
import { IgcTreeGridComponent } from 'igniteui-webcomponents-grids/grids';
import { OrdersTreeDataItem, OrdersTreeData } from './OrdersTreeData';
import { IgcPropertyEditorPropertyDescriptionChangedEventArgs } from 'igniteui-webcomponents-layouts';
import "igniteui-webcomponents-grids/grids/themes/light/bootstrap.css";
import 'igniteui-webcomponents/themes/light/bootstrap.css';
import { defineAllComponents } from 'igniteui-webcomponents';
import { ModuleManager } from 'igniteui-webcomponents-core';
defineAllComponents();
import "./index.css";
ModuleManager.register(
IgcPropertyEditorPanelModule
);
export class Sample {
private propertyEditorPanel1: IgcPropertyEditorPanelComponent
private summaryCalculationModeEditor: IgcPropertyEditorPropertyDescriptionComponent
private summaryPositionEditor: IgcPropertyEditorPropertyDescriptionComponent
private showSummaryOnCollapseEditor: IgcPropertyEditorPropertyDescriptionComponent
private treeGrid: IgcTreeGridComponent
private _bind: () => void;
constructor() {
var propertyEditorPanel1 = this.propertyEditorPanel1 = document.getElementById('propertyEditorPanel1') as IgcPropertyEditorPanelComponent;
var summaryCalculationModeEditor = this.summaryCalculationModeEditor = document.getElementById('SummaryCalculationModeEditor') as IgcPropertyEditorPropertyDescriptionComponent;
this.webTreeGridChangeSummaryCalculationMode = this.webTreeGridChangeSummaryCalculationMode.bind(this);
var summaryPositionEditor = this.summaryPositionEditor = document.getElementById('SummaryPositionEditor') as IgcPropertyEditorPropertyDescriptionComponent;
this.webTreeGridChangeSummaryPosition = this.webTreeGridChangeSummaryPosition.bind(this);
var showSummaryOnCollapseEditor = this.showSummaryOnCollapseEditor = document.getElementById('ShowSummaryOnCollapseEditor') as IgcPropertyEditorPropertyDescriptionComponent;
var treeGrid = this.treeGrid = document.getElementById('treeGrid') as IgcTreeGridComponent;
this._bind = () => {
propertyEditorPanel1.componentRenderer = this.renderer;
propertyEditorPanel1.target = this.treeGrid;
summaryCalculationModeEditor.changed = this.webTreeGridChangeSummaryCalculationMode;
summaryPositionEditor.changed = this.webTreeGridChangeSummaryPosition;
treeGrid.data = this.ordersTreeData;
}
this._bind();
}
private _ordersTreeData: OrdersTreeData = null;
public get ordersTreeData(): OrdersTreeData {
if (this._ordersTreeData == null)
{
this._ordersTreeData = new OrdersTreeData();
}
return this._ordersTreeData;
}
private _componentRenderer: ComponentRenderer = null;
public get renderer(): ComponentRenderer {
if (this._componentRenderer == null) {
this._componentRenderer = new ComponentRenderer();
var context = this._componentRenderer.context;
PropertyEditorPanelDescriptionModule.register(context);
WebTreeGridDescriptionModule.register(context);
}
return this._componentRenderer;
}
public webTreeGridChangeSummaryCalculationMode(sender: any, args: IgcPropertyEditorPropertyDescriptionChangedEventArgs): void {
var treeGrid = document.getElementById('treeGrid') as IgcTreeGridComponent;
treeGrid.summaryCalculationMode = args.newValue;
}
public webTreeGridChangeSummaryPosition(sender: any, args: IgcPropertyEditorPropertyDescriptionChangedEventArgs): void {
var treeGrid = document.getElementById('treeGrid') as IgcTreeGridComponent;
treeGrid.summaryPosition = args.newValue;
}
}
new Sample();
ts<!DOCTYPE html>
<html>
<head>
<title>Sample | Ignite UI | Web Components | infragistics</title>
<meta charset="UTF-8" />
<link rel="shortcut icon" href="https://static.infragistics.com/xplatform/images/browsers/wc.png" >
<link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons" />
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Kanit&display=swap" />
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Titillium Web" />
<link rel="stylesheet" href="https://static.infragistics.com/xplatform/css/samples/shared.v8.css" />
<link rel="stylesheet" href="/src/index.css" type="text/css" />
</head>
<body>
<div id="root">
<div class="container sample ig-typography">
<div class="options vertical">
<igc-property-editor-panel
description-type="WebTreeGrid"
is-horizontal="true"
is-wrapping-enabled="false"
name="propertyEditorPanel1"
id="propertyEditorPanel1">
<igc-property-editor-property-description
name="SummaryCalculationModeEditor"
id="SummaryCalculationModeEditor"
label="Summary Calculation Mode"
value-type="EnumValue"
drop-down-names="rootLevelOnly, childLevelsOnly, rootAndChildLevels"
drop-down-values="rootLevelOnly, childLevelsOnly, rootAndChildLevels">
</igc-property-editor-property-description>
<igc-property-editor-property-description
name="SummaryPositionEditor"
id="SummaryPositionEditor"
label="Summary Position"
value-type="EnumValue"
drop-down-names="top, bottom"
drop-down-values="top, bottom">
</igc-property-editor-property-description>
<igc-property-editor-property-description
label="Show summary row when group row is collapsed:"
property-path="ShowSummaryOnCollapse"
name="ShowSummaryOnCollapseEditor"
id="ShowSummaryOnCollapseEditor">
</igc-property-editor-property-description>
</igc-property-editor-panel>
</div>
<div class="container fill">
<igc-tree-grid
auto-generate="false"
name="treeGrid"
id="treeGrid"
id="treeGrid"
primary-key="ID"
foreign-key="ParentID">
<igc-column
field="ID"
header="Order ID"
sortable="true">
</igc-column>
<igc-column
field="Name"
header="Order Product"
has-summary="true">
</igc-column>
<igc-column
field="UnitPrice"
header="Price"
data-type="number"
has-summary="true"
editable="true">
</igc-column>
<igc-column
field="Delivered"
data-type="boolean">
</igc-column>
<igc-column
field="OrderDate"
header="Order Date"
data-type="date">
</igc-column>
</igc-tree-grid>
</div>
</div>
</div>
<!-- This script is needed only for parcel and it will be excluded for webpack -->
<% if (false) { %><script src="src/index.ts"></script><% } %>
</body>
</html>
html/* shared styles are loaded from: */
/* https://static.infragistics.com/xplatform/css/samples */
css
키보드 탐색
요약 행은 다음 키보드 상호 작용을 통해 탐색할 수 있습니다.
- UP- 한 셀 위로 이동합니다.
- DOWN- 한 셀 아래로 이동합니다.
- 왼쪽- 한 셀 왼쪽으로 이동합니다.
- RIGHT- 한 셀 오른쪽으로 이동합니다.
- CTRL + LEFT 또는 HOME- 가장 왼쪽 셀로 이동합니다.
- CTRL + RIGHT 또는 END- 가장 오른쪽 셀로 이동합니다.
스타일링
사전 정의된 테마 외에도 사용 가능한 CSS 속성 중 일부를 설정하여 그리드를 추가로 사용자 정의할 수 있습니다. 일부 색상을 변경하려면 먼저 그리드에 대한 클래스를 설정해야 합니다.
<igc-tree-grid class="grid"></igc-tree-grid>
html
그런 다음 해당 클래스에 대한 관련 CSS 속성을 설정합니다.
.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
데모
export class OrdersTreeDataItem {
public constructor(init: Partial<OrdersTreeDataItem>) {
Object.assign(this, init);
}
public ID: number;
public ParentID: number;
public Name: string;
public Category: string;
public OrderDate: string;
public Units: number;
public UnitPrice: number;
public Price: number;
public Delivered: boolean;
}
export class OrdersTreeData extends Array<OrdersTreeDataItem> {
public constructor(items: Array<OrdersTreeDataItem> | number = -1) {
if (Array.isArray(items)) {
super(...items);
} else {
const newItems = [
new OrdersTreeDataItem(
{
ID: 1,
ParentID: -1,
Name: `Order 1`,
Category: ``,
OrderDate: `2010-02-17`,
Units: 1844,
UnitPrice: 3.73,
Price: 6884.38,
Delivered: true
}),
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
}),
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
}),
new OrdersTreeDataItem(
{
ID: 103,
ParentID: 1,
Name: `Butter`,
Category: `Diary`,
OrderDate: `2010-02-17`,
Units: 260,
UnitPrice: 3.45,
Price: 897,
Delivered: true
}),
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
}),
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
}),
new OrdersTreeDataItem(
{
ID: 2,
ParentID: -1,
Name: `Order 2`,
Category: ``,
OrderDate: `2022-05-27`,
Units: 1831,
UnitPrice: 8.23,
Price: 15062.77,
Delivered: false
}),
new OrdersTreeDataItem(
{
ID: 201,
ParentID: 2,
Name: `Frozen Shrimps`,
Category: `Seafood`,
OrderDate: `2022-05-27`,
Units: 120,
UnitPrice: 20.45,
Price: 2454,
Delivered: false
}),
new OrdersTreeDataItem(
{
ID: 202,
ParentID: 2,
Name: `Ice Tea`,
Category: `Beverages`,
OrderDate: `2022-05-27`,
Units: 840,
UnitPrice: 7,
Price: 5880,
Delivered: false
}),
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
}),
new OrdersTreeDataItem(
{
ID: 204,
ParentID: 2,
Name: `Carrots`,
Category: `Vegetables`,
OrderDate: `2022-05-27`,
Units: 360,
UnitPrice: 2.77,
Price: 997.2,
Delivered: false
}),
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
}),
new OrdersTreeDataItem(
{
ID: 3,
ParentID: -1,
Name: `Order 3`,
Category: ``,
OrderDate: `2022-08-04`,
Units: 1972,
UnitPrice: 3.47,
Price: 6849.18,
Delivered: true
}),
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
}),
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
}),
new OrdersTreeDataItem(
{
ID: 303,
ParentID: 3,
Name: `Cauliflower`,
Category: `Vegetables`,
OrderDate: `2022-08-04`,
Units: 283,
UnitPrice: 0.95,
Price: 268.85,
Delivered: true
}),
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
}),
new OrdersTreeDataItem(
{
ID: 4,
ParentID: -1,
Name: `Order 4`,
Category: ``,
OrderDate: `2023-01-04`,
Units: 1065,
UnitPrice: 5.56,
Price: 5923.5,
Delivered: true
}),
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
}),
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
}),
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
}),
new OrdersTreeDataItem(
{
ID: 404,
ParentID: 4,
Name: `Potatoes`,
Category: `Vegetables`,
OrderDate: `2023-01-04`,
Units: 240,
UnitPrice: 1.6,
Price: 384,
Delivered: true
}),
];
super(...newItems.slice(0));
}
}
}
tsimport 'igniteui-webcomponents-grids/grids/combined';
import { ComponentRenderer, WebTreeGridDescriptionModule } from 'igniteui-webcomponents-core';
import { IgcTreeGridComponent, IgcColumnComponent } from 'igniteui-webcomponents-grids/grids';
import { OrdersTreeDataItem, OrdersTreeData } from './OrdersTreeData';
import { IgcColumnTemplateContext } from 'igniteui-webcomponents-grids/grids';
import { html, nothing } from 'lit-html';
import "igniteui-webcomponents-grids/grids/themes/light/bootstrap.css";
import "./index.css";
export class Sample {
private treeGrid: IgcTreeGridComponent
private column1: IgcColumnComponent
private column2: IgcColumnComponent
private column3: IgcColumnComponent
private column4: IgcColumnComponent
private column5: IgcColumnComponent
private column6: IgcColumnComponent
private column7: IgcColumnComponent
private _bind: () => void;
constructor() {
var treeGrid = this.treeGrid = document.getElementById('treeGrid') as IgcTreeGridComponent;
var column1 = this.column1 = document.getElementById('column1') as IgcColumnComponent;
var column2 = this.column2 = document.getElementById('column2') as IgcColumnComponent;
var column3 = this.column3 = document.getElementById('column3') as IgcColumnComponent;
var column4 = this.column4 = document.getElementById('column4') as IgcColumnComponent;
var column5 = this.column5 = document.getElementById('column5') as IgcColumnComponent;
var column6 = this.column6 = document.getElementById('column6') as IgcColumnComponent;
var column7 = this.column7 = document.getElementById('column7') as IgcColumnComponent;
this._bind = () => {
treeGrid.data = this.ordersTreeData;
column1.headerTemplate = this.webTreeGridSummariesHeaderTemplate;
column2.headerTemplate = this.webTreeGridSummariesHeaderTemplate;
column3.headerTemplate = this.webTreeGridSummariesHeaderTemplate;
column4.headerTemplate = this.webTreeGridSummariesHeaderTemplate;
column5.headerTemplate = this.webTreeGridSummariesHeaderTemplate;
column6.headerTemplate = this.webTreeGridSummariesHeaderTemplate;
column7.headerTemplate = this.webTreeGridSummariesHeaderTemplate;
}
this._bind();
}
private _ordersTreeData: OrdersTreeData = null;
public get ordersTreeData(): OrdersTreeData {
if (this._ordersTreeData == null)
{
this._ordersTreeData = new OrdersTreeData();
}
return this._ordersTreeData;
}
private _componentRenderer: ComponentRenderer = null;
public get renderer(): ComponentRenderer {
if (this._componentRenderer == null) {
this._componentRenderer = new ComponentRenderer();
var context = this._componentRenderer.context;
WebTreeGridDescriptionModule.register(context);
}
return this._componentRenderer;
}
public webTreeGridSummariesHeaderTemplate = (ctx: IgcColumnTemplateContext) => {
const column = (ctx as any).column;
return html`<div>
<span style="float:left">${column.field}</span>
<span style="float:right; color: ${column.hasSummary ? '#e41c77' : ''}" @pointerdown=${(e: any) => this.toggleSummary(column)}>∑</span>
</div>`;
};
public toggleSummary(field: IgcColumnComponent) {
if (field) {
field.hasSummary = !field.hasSummary;
}
}
}
new Sample();
ts<!DOCTYPE html>
<html>
<head>
<title>Sample | Ignite UI | Web Components | infragistics</title>
<meta charset="UTF-8" />
<link rel="shortcut icon" href="https://static.infragistics.com/xplatform/images/browsers/wc.png" >
<link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons" />
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Kanit&display=swap" />
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Titillium Web" />
<link rel="stylesheet" href="https://static.infragistics.com/xplatform/css/samples/shared.v8.css" />
<link rel="stylesheet" href="/src/index.css" type="text/css" />
</head>
<body>
<div id="root">
<div class="container sample ig-typography">
<div class="container fill">
<igc-tree-grid
auto-generate="false"
name="treeGrid"
id="treeGrid"
id="treeGrid"
primary-key="ID"
foreign-key="ParentID">
<igc-column
field="ID"
header="Order ID">
</igc-column>
<igc-column
field="Name"
header="Order Product"
has-summary="true"
name="column1"
id="column1">
</igc-column>
<igc-column
field="Category"
header="Category"
has-summary="true"
name="column2"
id="column2">
</igc-column>
<igc-column
field="Units"
header="Units"
data-type="number"
has-summary="true"
editable="true"
name="column3"
id="column3">
</igc-column>
<igc-column
field="UnitPrice"
header="Unit Price"
data-type="number"
has-summary="true"
editable="true"
name="column4"
id="column4">
</igc-column>
<igc-column
field="Price"
header="Price"
data-type="number"
has-summary="true"
editable="true"
name="column5"
id="column5">
</igc-column>
<igc-column
field="Delivered"
header="Delivered"
data-type="boolean"
has-summary="true"
name="column6"
id="column6">
</igc-column>
<igc-column
field="OrderDate"
header="Order Date"
data-type="date"
has-summary="true"
name="column7"
id="column7">
</igc-column>
</igc-tree-grid>
</div>
</div>
</div>
<!-- This script is needed only for parcel and it will be excluded for webpack -->
<% if (false) { %><script src="src/index.ts"></script><% } %>
</body>
</html>
html/* shared styles are loaded from: */
/* 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 참조
추가 리소스
우리 커뮤니티는 활동적이며 항상 새로운 아이디어를 환영합니다.