Web Components Tree Grid Summaries
The Ignite UI for Web Components Summaries feature in Web Components Tree Grid functions on a per-column level as group footer. Web Components IgcTreeGrid 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 IgcTreeGridComponent.
Web Components Tree Grid Summaries Overview Example
[!Note] 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
IgcTreeGridComponent요약은 Ignite UI for Web Components에서 열별로 활성화할 수 있어, 필요한 열에만 활성화할 수 있습니다.IgcTreeGridComponent 요약은 열의 데이터 유형에 따라 미리 정의된 기본 요약 집합을 제공하여 시간을 절약할 수 있습니다:
때문에string 그리고boolean dataType, 다음과 같은 함수가 제공됩니다:
- 세다
데이터 유형에 대해서는numbercurrencypercent 다음과 같은 함수들이 제공됩니다:
- 세다
- 최소
- 맥스
- 평균
- 합집합
데이터 타입의 경우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>
특정 열이나 열의 목록에 대한 요약을 활성화하거나 비활성화하는 또 다른 방법은 공개enableSummaries 메서드disableSummariesIgcTreeGridComponent를 사용하는 것입니다.
<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>
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);
}
public enableSummary() {
this.treeGrid.enableSummaries([
{fieldName: 'Name'},
{fieldName: 'Units'}
]);
}
public disableSummary() {
this.treeGrid.disableSummaries(['Units']);
}
Custom Tree Grid Summaries
이러한 기능이 요구 사항을 충족하지 못하는 경우 특정 열에 대한 사용자 정의 요약을 제공할 수 있습니다.
이를 위해서는 기본 클래스IgcSummaryOperand 중 하나를 오버라이드해야 하거나,IgcNumberSummaryOperandIgcDateSummaryOperand 열의 데이터 타입과 필요에 따라 다릅니다. 이렇게 하면 기존 함수를 재정의하거나 새로운 함수를 추가할 수 있습니다.IgcSummaryOperand 클래스는 메서드에count 대한 기본 구현만 제공합니다.IgcNumberSummaryOperand 확장IgcSummaryOperand 하고 구현MinMaxSumAverage을 제공합니다.IgcDateSummaryOperand 확장IgcSummaryOperand 하고 추가로 제공합니다EarliestLatest.
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;
}
}
예시에서 볼 수 있듯이, 기본 클래스는 메서드를operate 노출시키므로 모든 기본 요약을 가져와 결과를 수정하거나 완전히 새로운 요약 결과를 계산할 수 있습니다.
메서드는 의IgcSummaryResult 리스트를 반환합니다.
interface IgcSummaryResult {
key: string;
label: string;
summaryResult: any;
}
요약을 계산하기 위해 선택적 매개변수를 사용합니다. 아래의 모든 데이터 섹션에 액세스하는 사용자 정의 요약을 참조하세요.
[!Note] In order to calculate the summary row height properly, the Tree Grid needs the
operatemethod to always return an array ofIgcSummaryResultwith the proper length even when the data is empty.
And now let's add our custom summary to the column title. We will achieve that by setting the Summaries` property to the class we create below.
<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>
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;
}
export class TreeGridComponent implements OnInit {
mySummary = MySummary;
}
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 - 현재 열의 값만 포함하는 배열을 제공합니다.
- 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;
}
}
Summary Template
summaryTemplate요약 열을 타겟팅하여 요약 열의 결과를 맥락으로 제공합니다.
<igc-column id="column" has-summary="true">
</igc-column>
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>
`;
}
기본 요약이 정의되면, 요약 영역의 높이는 요약 개수가 가장 많은 열과--ig-size 격자의 위치에 따라 설계되어 계산됩니다. 입력 속성을 사용summaryRowHeight 해 기본값을 덮어쓰세요. 인수로서 숫자 값을 기대하며, 가짜 값을 설정하면 그리드 푸터의 기본 크기 동작이 촉발됩니다.
Disabled Summaries
The disabled-summaries property provides precise per-column control over the Web Components Tree Grid summary feature. This property enables users to customize the summaries displayed for each column in the IgcTreeGrid, 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.
또한 이 속성은 코드를 통해 런타임에 동적으로 수정할 수 있으므로 IgcTreeGrid의 요약을 애플리케이션 상태 또는 사용자 작업 변경에 맞게 유연하게 조정할 수 있습니다.
The following examples illustrate how to use the disabled-summaries property to manage summaries for different columns and exclude specific default and custom summary types in the Web Components Tree Grid:
<!-- 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>
예를 들어UnitPrice, 기본 요약 같은count 것들은 비활성화되어 있고,sumaverage 다른 것들은 좋아min 요와max 활성화된 상태로 남아 있습니다.
그리고UnitsInStock 같은 맞춤형 요약discontinuedtotalDiscontinued은 해당 속성을 사용할 때disabled-summaries 제외됩니다.
런타임에는 이 속성을 사용하여disabledSummaries 요약을 동적으로 비활성화할 수도 있습니다. 예를 들어, 특정 열의 속성을 프로그래밍적으로 설정하거나 업데이트하여 사용자 행동이나 애플리케이션 상태 변화에 따라 표시되는 요약을 조정할 수 있습니다.
Formatting summaries
기본적으로 내장된 요약 연산자에 의해 생성된 요약 결과는 그리드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;
}
<igc-column id="column"></igx-column>
constructor() {
var column = this.column = document.getElementById('column') as IgcColumnComponent;
column.summaryFormatter = this.dateSummaryFormat;
}
Child Summaries
The IgcTreeGridComponent 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 IgcTreeGridComponent exposes and showSummaryOnCollapse property which allows you to determine whether the summary row stays visible when the parent node that refers to is collapsed.
부동산의summaryCalculationMode 이용 가능한 가치는 다음과 같습니다:
RootLevelOnly- Summaries are calculated only for the root level nodes.ChildLevelsOnly- 요약은 자식 수준에만 적용됩니다.RootAndChildLevels- 요약은 루트 레벨과 자식 레벨 모두에 대해 계산됩니다. 이것이 기본 값입니다.
부동산의summaryPosition 이용 가능한 가치는 다음과 같습니다:
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.
[!Note] The
summaryPositionproperty applies only for the child level summaries. The root level summaries appear always fixed at the bottom of theIgcTreeGridComponent.
Keyboard Navigation
요약 행은 다음 키보드 상호 작용을 통해 탐색할 수 있습니다.
- UP- 한 셀 위로 이동합니다.
- DOWN- 한 셀 아래로 이동합니다.
- 왼쪽- 한 셀 왼쪽으로 이동합니다.
- RIGHT- 한 셀 오른쪽으로 이동합니다.
- CTRL + LEFT 또는 HOME- 가장 왼쪽 셀로 이동합니다.
- CTRL + RIGHT 또는 END- 가장 오른쪽 셀로 이동합니다.
Styling
사전 정의된 테마 외에도 사용 가능한 CSS 속성 중 일부를 설정하여 그리드를 추가로 사용자 정의할 수 있습니다. 일부 색상을 변경하려면 먼저 그리드에 대한 클래스를 설정해야 합니다.
<igc-tree-grid class="grid"></igc-tree-grid>
그런 다음 해당 클래스에 대한 관련 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;
}
Demo
API References
Additional Resources
우리 커뮤니티는 활동적이며 항상 새로운 아이디어를 환영합니다.