Angular 그리드 요약
Ignite UI for Angular의 Angular UI 그리드에는 그룹 푸터로 열 수준에서 작동하는 요약 기능이 있습니다. Angular 그리드 요약은 사용자가 열 내 데이터 유형에 따라 또는 그리드에서 사용자 정의 각도 템플릿을 구현하여 사전 정의된 기본 요약 항목 세트가 있는 별도의 컨테이너에서 열 정보를 볼 수 있게 해주는 강력한 기능입니다.
Angular Grid Summaries Overview Example
import { Component, ViewChild } from '@angular/core' ;
import { ColumnType, IgxGridComponent, IgxNumberSummaryOperand, IgxSummaryResult, IgxPaginatorComponent, IgxColumnComponent, IgxCellTemplateDirective, IgxCellHeaderTemplateDirective, IgxIconComponent } from 'igniteui-angular' ;
import { DATA } from '../../data/nwindData' ;
import { IgxPreventDocumentScrollDirective } from '../../directives/prevent-scroll.directive' ;
import { DatePipe } from '@angular/common' ;
class MySummary {
public operate(data?: any []): IgxSummaryResult[] {
const result = new IgxNumberSummaryOperand().operate(data);
result.push({
key : 'test' ,
label : 'Test' ,
summaryResult : data.filter((rec ) => rec > 10 && rec < 30 ).length
});
return result;
}
}
@Component ({
selector : 'app-grid-sample-3' ,
styleUrls : ['./grid-sample-3.component.scss' ],
templateUrl : './grid-sample-3.component.html' ,
imports : [IgxGridComponent, IgxPreventDocumentScrollDirective, IgxPaginatorComponent, IgxColumnComponent, IgxCellTemplateDirective, IgxCellHeaderTemplateDirective, IgxIconComponent, DatePipe]
})
export class GridSample3Component {
@ViewChild ('grid1' , { read : IgxGridComponent, static : true })
public grid1: IgxGridComponent;
public mySummary = MySummary;
public data;
public productId = 0 ;
constructor ( ) {
this .data = DATA;
this .productId = DATA.length;
}
public toggleSummary (column: ColumnType ) {
column.hasSummary = !column.hasSummary;
}
}
ts コピー <div class ="grid__wrapper" >
<igx-grid [igxPreventDocumentScroll ]="true" #grid1 [data ]="data" [autoGenerate ]="false" height ="600px" width ="100%" >
<igx-paginator > </igx-paginator >
<igx-column #col field ="ProductID" header ="Product ID" width ="17%" [headerClasses ]="'prodId'" >
</igx-column >
<igx-column #col field ="ProductName" header ="Product Name" width ="17%" [headerClasses ]="'prodId'" [hasSummary ]="true" >
<ng-template igxCell let-cell ="cell" let-val >
{{val}}
</ng-template >
<ng-template igxHeader let-col >
<div class ="header-text" > {{col.field}}</div >
<igx-icon class ="header-icon" style.color ="{{ col.hasSummary ? '#e41c77' : '' }}" (click )="toggleSummary(col)" > functions</igx-icon >
</ng-template >
</igx-column >
<igx-column #col field ="UnitPrice" header ="Price" [filterable ]="false" width ="17%" [editable ]="true" dataType ="number"
[hasSummary ]="true" >
<ng-template igxCell let-cell ="cell" let-val let-row >
${{val}}
</ng-template >
<ng-template igxHeader let-col >
<div class ="header-text" > {{col.field}}</div >
<igx-icon class ="header-icon" style.color ="{{ col.hasSummary ? '#e41c77' : '' }}" (click )="toggleSummary(col)" > functions</igx-icon >
</ng-template >
</igx-column >
<igx-column #col field ="UnitsInStock" header ="Units In Stock" width ="17%" dataType ="number" [editable ]="true"
[hasSummary ]="false" [summaries ]="mySummary" >
<ng-template igxCell let-cell ="cell" let-val let-row >
{{val}}
</ng-template >
<ng-template igxHeader let-col >
<div class ="header-text" > {{col.field}}</div >
<igx-icon class ="header-icon" style.color ="{{ col.hasSummary ? '#e41c77' : '' }}" (click )="toggleSummary(col)" > functions</igx-icon >
</ng-template >
</igx-column >
<igx-column #col field ="Discontinued" header ="Discontinued" width ="17%" [hasSummary ]="true" [dataType ]="'boolean'" >
<ng-template igxCell let-cell ="cell" let-val >
@if (val) {
<img src ="https://www.infragistics.com/angular-demos-lob/assets/images/grid/active.png" title ="Continued" alt ="Continued" />
}
@if (!val) {
<img src ="https://www.infragistics.com/angular-demos-lob/assets/images/grid/expired.png" title ="Discontinued" alt ="Discontinued" />
}
</ng-template >
<ng-template igxHeader let-col >
<div class ="header-text" > {{col.field}}</div >
<igx-icon class ="header-icon" style.color ="{{ col.hasSummary ? '#e41c77' : '' }}" (click )="toggleSummary(col)" > functions</igx-icon >
</ng-template >
</igx-column >
<igx-column #col field ="OrderDate" width ="15%" [dataType ]="'date'" [hasSummary ]="true" >
<ng-template igxCell let-cell ="cell" let-val let-row >
{{ val | date: 'MMM d, yyyy' }}
</ng-template >
<ng-template igxHeader let-col >
<div class ="header-text" > {{col.field}}</div >
<igx-icon class ="header-icon" style.color ="{{ col.hasSummary ? '#e41c77' : '' }}" (click )="toggleSummary(col)" > functions</igx-icon >
</ng-template >
</igx-column >
</igx-grid >
</div >
html コピー .grid-controls {
display : flex;
flex-flow : column nowrap;
justify-content : space-between;
margin : 0 16px 24px ;
igx-switch {
margin-top : 24px ;
}
}
.grid__wrapper {
margin : 0 auto;
padding : 16px ;
}
.header {
height : 100% ;
}
:host ::ng-deep{
.igx-grid__th .title{
width: 100% ;
cursor : auto;
}
@media screen and (max-width : 677px ){
.header-icon {
padding-bottom : 17px ;
padding-top : 17px ;
font-size : 1.4em ;
width : 1.1em ;
height : 1.1em ;
float : right;
}
.header-text {
float :left ;
white-space : nowrap;
overflow : hidden;
text-overflow : ellipsis;
width : 50% ;
}
}
@media screen and (min-width : 677px ){
.header-icon {
padding-top : 17px ;
font-size : 1.4em ;
width : 1.1em ;
height : 1.1em ;
float : right;
}
.header-text {
float :left ;
white-space : nowrap;
overflow : hidden;
text-overflow : ellipsis;
width : 50% ;
}
}
@media screen and (min-width : 992px ){
.header-icon {
padding-top : 17px ;
font-size : 1.4em ;
width : 1.1em ;
height : 1.1em ;
float : right;
margin-right : 10px ;
cursor : pointer;
}
.header-text {
float :left ;
white-space : nowrap;
width : 50% ;
cursor : auto;
}
}
}
scss コピー
Like this sample? Get access to our complete Ignite UI for Angular toolkit and start building your own apps in minutes. Download it for free.
열 요약은 모든 열 값의 함수 입니다. 필터링이 적용되지 않는 한 열 요약은 필터링된 결과 값의 함수 입니다.
Ignite UI for Angular에서 그리드 요약을 열 단위로 활성화할 수도 있습니다. 즉, 필요한 열에 대해서만 활성화할 수 있습니다. 그리드 요약은 열의 데이터 유형에 따라 미리 정의된 기본 요약 세트를 제공하므로 시간을 절약할 수 있습니다.
string
및 boolean
data types
의 경우 다음 함수를 사용할 수 있습니다.
number
, currency
및 percent
데이터 유형의 경우 다음 함수를 사용할 수 있습니다.
date
데이터 유형의 경우 다음 기능을 사용할 수 있습니다.
사용 가능한 모든 열 데이터 유형은 공식 열 유형 항목 에서 찾을 수 있습니다.
그리드 요약 설정을 통해 열별로 활성화됩니다. hasSummary
재산 true
. 각 열의 요약은 열 데이터 유형에 따라 결정된다는 점을 명심하는 것도 중요합니다. 에서 igx-grid
기본 열 데이터 유형은 다음과 같습니다. string
, 그러니 원한다면 number
또는 date
특정 요약을 지정해야 합니다. dataType
재산 number
또는 date
. 요약 값은 그리드에 따라 현지화되어 표시됩니다. locale
및 열 pipeArgs
.
<igx-grid #grid1 [data ]="data" [autoGenerate ]="false" height ="800px" width ="800px" (columnInit )="initColumn($event)" >
<igx-column field ="ProductID" header ="Product ID" width ="200px" [sortable ]="true" > </igx-column >
<igx-column field ="ProductName" header ="Product Name" width ="200px" [sortable ]="true" [hasSummary ]="true" > </igx-column >
<igx-column field ="ReorderLevel" width ="200px" [editable ]="true" [dataType ]="'number'" [hasSummary ]="true" > </igx-column >
</igx-grid >
html
특정 열이나 열 목록에 대한 요약을 활성화/비활성화하는 다른 방법은 public 메서드를 사용하는 것입니다. enableSummaries
/ disableSummaries
~의 igx-그리드 .
<igx-grid #grid1 [data ]="data" [autoGenerate ]="false" height ="800px" width ="800px" (columnInit )="initColumn($event)" >
<igx-column field ="ProductID" header ="Product ID" width ="200px" [sortable ]="true" > </igx-column >
<igx-column field ="ProductName" header ="Product Name" width ="200px" [sortable ]="true" [hasSummary ]="true" > </igx-column >
<igx-column field ="ReorderLevel" width ="200px" [editable ]="true" [dataType ]="'number'" [hasSummary ]="false" > </igx-column >
</igx-grid >
<button (click )="enableSummary()" > Enable Summary</button >
<button (click )="disableSummary()" > Disable Summary </button >
html
public enableSummary ( ) {
this .grid1.enableSummaries([
{fieldName : 'ReorderLevel' , customSummary : this .mySummary},
{fieldName : 'ProductID' }
]);
}
public disableSummary ( ) {
this .grid1.disableSummaries('ProductName' );
}
typescript
Custom Grid Summaries
이러한 기능이 요구 사항을 충족하지 못하는 경우 특정 열에 대한 사용자 정의 요약을 제공할 수 있습니다. 이를 달성하려면 열 데이터 유형 및 필요에 따라 기본 클래스 IgxSummaryOperand
, IgxNumberSummaryOperand
또는 IgxDateSummaryOperand
중 하나를 재정의해야 합니다. 이 방법으로 기존 기능을 재정의하거나 새 기능을 추가할 수 있습니다. IgxSummaryOperand
클래스는 count
메소드에 대해서만 기본 구현을 제공합니다. IgxNumberSummaryOperand
IgxSummaryOperand
확장하고 min
, max
, sum
및 average
에 대한 구현을 제공합니다. IgxDateSummaryOperand
IgxSummaryOperand
확장하고 추가적으로 earliest
및 latest
.
import { IgxSummaryResult, IgxSummaryOperand, IgxNumberSummaryOperand, IgxDateSummaryOperand } from 'igniteui-angular' ;
class MySummary extends IgxNumberSummaryOperand {
constructor ( ) {
super ();
}
operate(data?: any []): IgxSummaryResult[] {
const result = super .operate(data);
result.push({
key : 'test' ,
label : 'Test' ,
summaryResult : data.filter(rec => rec > 10 && rec < 30 ).length
});
return result;
}
}
typescript
예제에서 볼 수 있듯이 기본 클래스는 operate
메서드를 노출하므로 모든 기본 요약을 가져오고 결과를 수정하거나 완전히 새로운 요약 결과를 계산하도록 선택할 수 있습니다. 이 메소드는 IgxSummaryResult
목록을 반환합니다.
interface IgxSummaryResult {
key : string ;
label: string ;
summaryResult: any ;
}
typescript
요약을 계산하기 위해 선택적 매개변수를 사용합니다. 아래의 모든 데이터 섹션에 액세스하는 사용자 정의 요약을 참조하세요.
이제 UnitsInStock
열에 사용자 정의 요약을 추가해 보겠습니다. 아래에서 생성한 클래스에 summaries
속성을 설정하여 이를 달성하겠습니다.
<igx-grid #grid1 [data ]="data" [autoGenerate ]="false" height ="800px" width ="800px" (columnInit )="initColumn($event)" >
<igx-column field ="ProductID" width ="200px" [sortable ]="true" >
</igx-column >
<igx-column field ="ProductName" width ="200px" [sortable ]="true" [hasSummary ]="true" >
</igx-column >
<igx-column field ="UnitsInStock" width ="200px" [dataType ]="'number'" [hasSummary ]="true" [summaries ]="mySummary" [sortable ]="true" >
</igx-column >
<igx-column field ="ReorderLevel" width ="200px" [editable ]="true" [dataType ]="'number'" [hasSummary ]="true" >
</igx-column >
</igx-grid >
html
...
export class GridComponent implements OnInit {
mySummary = MySummary;
....
}
typescript
Custom summaries, which access all data
이제 사용자 정의 열 요약 내의 모든 그리드 데이터에 액세스할 수 있습니다. IgxSummaryOperand operate
메소드에는 두 개의 추가 선택적 매개변수가 도입되었습니다. 아래 코드 조각에서 볼 수 있듯이 Operate 메소드에는 다음 세 가지 매개변수가 있습니다.
columnData - 현재 열의 값만 포함하는 배열을 제공합니다.
allGridData - 전체 그리드 데이터 소스를 제공합니다.
fieldName - 현재 열 필드
class MySummary extends IgxNumberSummaryOperand {
constructor ( ) {
super ();
}
operate(columnData: any [], allGridData = [], fieldName?): IgxSummaryResult[] {
const result = super .operate(allData.map(r => r[fieldName]));
result.push({ key : 'test' , label : 'Total Discontinued' , summaryResult : allData.filter((rec ) => rec.Discontinued).length });
return result;
}
}
typescript
import { Component, ViewChild } from '@angular/core' ;
import { IgxGridComponent, IgxNumberSummaryOperand, IgxSummaryResult, IgxPaginatorComponent, IgxColumnComponent } from 'igniteui-angular' ;
import { DATA } from '../../data/nwindData' ;
import { IgxPreventDocumentScrollDirective } from '../../directives/prevent-scroll.directive' ;
class DiscontinuedSummary {
public operate(data?: any [], allData = [], fieldName = '' ): IgxSummaryResult[] {
const result = [];
result.push({
key : 'products' ,
label : 'Products' ,
summaryResult : data.length
});
result.push({
key : 'total' ,
label : 'Total Items' ,
summaryResult : IgxNumberSummaryOperand.sum(data)
});
result.push({
key : 'discontinued' ,
label : 'Discontinued Products' ,
summaryResult : allData.map(r => r['Discontinued' ]).filter((rec ) => rec).length
});
result.push({
key : 'totalDiscontinued' ,
label : 'Total Discontinued Items' ,
summaryResult : IgxNumberSummaryOperand.sum(allData.filter((rec ) => rec['Discontinued' ]).map(r => r[fieldName]))
});
return result;
}
}
@Component ({
selector : 'app-grid-all-data-summary' ,
styleUrls : ['./grid-allData-summary.component.scss' ],
templateUrl : './grid-allData-summary.component.html' ,
imports : [IgxGridComponent, IgxPreventDocumentScrollDirective, IgxPaginatorComponent, IgxColumnComponent]
})
export class GridAllDataSummaryComponent {
@ViewChild ('grid1' , { read : IgxGridComponent, static : true })
public grid1: IgxGridComponent;
public discontinuedSummary = DiscontinuedSummary;
public data;
constructor ( ) {
this .data = DATA;
}
}
ts コピー <div class ="grid__wrapper" >
<igx-grid [igxPreventDocumentScroll ]="true" #grid1 [data ]="data" [autoGenerate ]="false" height ="600px" width ="100%" >
@if (false) {
<igx-paginator > </igx-paginator >
}
<igx-column field ="ProductID" header ="Product ID" width ="17%" [headerClasses ]="'prodId'" >
</igx-column >
<igx-column field ="ProductName" header ="Product Name" width ="17%" [headerClasses ]="'prodId'" >
</igx-column >
<igx-column field ="UnitPrice" header ="Price" [filterable ]="false" width ="17%" [editable ]="true" dataType ="number" >
</igx-column >
<igx-column field ="UnitsInStock" header ="Units In Stock" width ="17%" dataType ="number" [editable ]="true"
[hasSummary ]="true" [summaries ]="discontinuedSummary" >
</igx-column >
<igx-column field ="Discontinued" header ="Discontinued" [editable ]="true" width ="17%" [dataType ]="'boolean'" >
</igx-column >
<igx-column field ="OrderDate" width ="15%" [dataType ]="'date'" [hasSummary ]="true" >
</igx-column >
</igx-grid >
</div >
html コピー .grid__wrapper {
margin : 0 auto;
padding : 16px ;
}
scss コピー
Summary Template
igxSummary
열 요약 결과를 컨텍스트로 제공하는 열 요약을 대상으로 합니다.
<igx-column ... [hasSummary ]="true" >
<ng-template igxSummary let-summaryResults >
<span > My custom summary template</span >
<span > {{ summaryResults[0].label }} - {{ summaryResults[0].summaryResult }}</span >
</ng-template >
</igx-column >
html
기본 요약이 정의되면 요약 영역의 높이는 요약 수가 가장 많은 열과 그리드의 크기에 따라 설계에 따라 계산됩니다. summaryRowHeight 입력 속성을 사용하여 디폴트 값을 재정의합니다. 인수로 숫자 값이 필요하며 false 값을 설정하면 그리드 바닥글의 기본 크기 조정 동작이 트리거됩니다.
import { Component, HostBinding, OnInit } from '@angular/core' ;
import { IgxNumberSummaryOperand, IgxSummaryResult, IgxInputGroupComponent, IgxLabelDirective, IgxInputDirective, IgxSwitchComponent, IgxButtonGroupComponent, IgxGridComponent, IgxColumnComponent, IgxSummaryTemplateDirective } from 'igniteui-angular' ;
import { DATA } from '../../data/nwindData' ;
import { FormsModule } from '@angular/forms' ;
import { IgxPreventDocumentScrollDirective } from '../../directives/prevent-scroll.directive' ;
class DiscontinuedSummary {
public operate(data?: any [], allData = [], fieldName = '' ): IgxSummaryResult[] {
const result = [];
result.push({
key : 'products' ,
label : 'Products' ,
summaryResult : data.length
});
result.push({
key : 'total' ,
label : 'Total Items' ,
summaryResult : IgxNumberSummaryOperand.sum(data)
});
result.push({
key : 'discontinued' ,
label : 'Discontinued Products' ,
summaryResult : allData.map(r => r['Discontinued' ]).filter((rec ) => rec).length
});
result.push({
key : 'totalDiscontinued' ,
label : 'Total Discontinued Items' ,
summaryResult : IgxNumberSummaryOperand.sum(allData.filter((rec ) => rec['Discontinued' ]).map(r => r[fieldName]))
});
return result;
}
}
@Component ({
selector : 'app-grid-summary-template' ,
styleUrls : ['./grid-summary-template.component.scss' ],
templateUrl : './grid-summary-template.component.html' ,
imports : [IgxInputGroupComponent, IgxLabelDirective, FormsModule, IgxInputDirective, IgxSwitchComponent, IgxButtonGroupComponent, IgxGridComponent, IgxPreventDocumentScrollDirective, IgxColumnComponent, IgxSummaryTemplateDirective]
})
export class GridSummaryTemplateComponent implements OnInit {
public discontinuedSummary = DiscontinuedSummary;
public data;
public summaryHeight = 135 ;
public size = 'medium' ;
public sizes;
public hasSummary = true ;
constructor ( ) {
this .data = DATA;
}
public ngOnInit(): void {
this .sizes = [
{ label : 'small' , selected : this .size === 'small' , togglable : true },
{ label : 'medium' , selected : this .size === 'medium' , togglable : true },
{ label : 'large' , selected : this .size === 'large' , togglable : true }
];
}
public selectSize(event): void {
this .size = this .sizes[event.index].label;
}
@HostBinding ('style.--ig-size' )
protected get sizeStyle () {
return `var(--ig-size-${this .size} )` ;
}
}
ts コピー <div class ="sample__wrapper" >
<div class ="controls-wrapper" >
<igx-input-group >
<label igxLabel for ="height" > Summary Row Height</label >
<input igxInput name ="height" type ="number" [(ngModel )]="summaryHeight" >
</igx-input-group >
<igx-switch [(ngModel )]="hasSummary" > Toggle Summaries</igx-switch >
<igx-buttongroup [values ]="sizes" (selected )="selectSize($event)" >
</igx-buttongroup >
</div >
<igx-grid [igxPreventDocumentScroll ]="true" #grid1 [data ]="data"
[summaryRowHeight ]="summaryHeight" [autoGenerate ]="false" height ="550px" width ="100%" >
<igx-column field ="ProductID" header ="Product ID" width ="10%" [headerClasses ]="'prodId'" [groupable ]="true" >
</igx-column >
<igx-column field ="ProductName" header ="Product Name" width ="17%" [headerClasses ]="'prodId'" [groupable ]="true" >
</igx-column >
<igx-column field ="UnitPrice" header ="Price" [filterable ]="false" width ="17%" [editable ]="true" dataType ="number" [groupable ]="true" >
</igx-column >
<igx-column field ="UnitsInStock" header ="Units In Stock" width ="21%" dataType ="number" [editable ]="true"
[hasSummary ]="hasSummary" [summaries ]="discontinuedSummary" [groupable ]="true" >
</igx-column >
<igx-column field ="Discontinued" header ="Discontinued" [editable ]="true" width ="17%" [dataType ]="'boolean'" [groupable ]="true" >
</igx-column >
<igx-column field ="OrderDate" width ="18%" [dataType ]="'date'" [hasSummary ]="hasSummary" [groupable ]="true" >
<ng-template igxSummary let-summaryResults >
<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 >
</div >
</ng-template >
</igx-column >
</igx-grid >
</div >
html コピー .sample__wrapper {
display : flex;
flex-direction : column;
gap: 16px ;
padding : 16px ;
height : 100% ;
overflow-y : auto;
}
igx-buttongroup {
max-width : 450px ;
flex : 1 ;
}
.summary-temp {
display : flex;
flex-direction : column;
margin : 0 1px ;
font-size : 14px ;
line-height : 24px ;
height : 100% ;
overflow-y : auto;
overflow-x : hidden;
span {
display : flex;
flex-wrap : wrap;
align-items : center;
gap: 4px ;
justify-content : space-between;
color : hsla(var(--igx-gray-900 ));
span {
user-select: all;
max-width : 300px ;
padding-right : 8px ;
}
strong {
font-size : 12px ;
text-transform : uppercase;
min-width : 70px ;
justify-self: flex-start;
text-align : left;
color : var(--ig-secondary-600 );
user-select: none;
}
}
> * {
padding : 8px 0 ;
line-height : 18px ;
border-bottom : 1px dashed hsla(var(--igx-gray-400 ));
&:last-child {
border-bottom : none;
}
}
}
::-webkit-scrollbar {
width: 5px !important ;
height : 5px !important ;
}
.controls-wrapper {
display : flex;
align-items : center;
flex-direction : row;
gap: 16px ;
}
scss コピー
Disable Summaries
이 disabledSummaries
속성은 Ignite UI for Angular 그리드 요약 기능에 대한 정확한 열 별 제어를 제공합니다. 이 속성을 사용하면 사용자가 그리드의 각 열에 대해 표시되는 요약을 사용자 지정하여 가장 관련성이 높고 의미 있는 데이터만 표시되도록 할 수 있습니다. 예를 들어, 배열에서 요약 키를 지정하는 등의 ['count', 'min', 'max']
특정 요약 유형을 제외할 수 있습니다.
또한 이 속성은 코드를 통해 런타임에 동적으로 수정할 수 있으므로 변화하는 응용 프로그램 상태 또는 사용자 작업에 맞게 그리드의 요약을 조정할 수 있는 유연성을 제공합니다.
다음 예제에서는 속성을 사용하여 disabledSummaries
여러 열에 대한 요약을 관리하고 Ignite UI for Angular 그리드에서 특정 기본 및 사용자 지정 요약 유형을 제외하는 방법을 보여 줍니다.
<igx-column
field ="UnitPrice"
header ="Unit Price"
dataType ="number"
[hasSummary ]="true"
[disabledSummaries ]="['count', 'sum', 'average']"
>
</igx-column >
<igx-column
field ="UnitsInStock"
header ="Units In Stock"
dataType ="number"
[hasSummary ]="true"
[summaries ]="discontinuedSummary"
[disabledSummaries ]="['discontinued', 'totalDiscontinued']"
>
</igx-column >
html
의 UnitPrice
경우, 기본 요약은 , sum
와 average
같고 count
비활성화되어 있으며 다른 요약은 같고 min
max
활성 상태로 유지됩니다.
의 UnitsInStock
경우 및 totalDiscontinued
와 같은 total
사용자 지정 요약은 속성을 사용하여 제외됩니다 disabledSummaries
.
런타임에 요약은 속성을 사용하여 동적으로 비활성화할 수도 있습니다 disabledSummaries
. 예를 들어, 프로그래밍 방식으로 특정 열의 속성을 설정하거나 업데이트하여 사용자 작업 또는 응용 프로그램 상태 변경에 따라 표시되는 요약을 조정할 수 있습니다.
기본적으로 기본 제공 요약 피연산자에 의해 생성된 요약 결과는 그리드 locale
및 pipeArgs
열에 따라 지역화되고 형식이 지정됩니다. 사용자 정의 피연산자를 사용하는 경우 locale
및 pipeArgs
적용되지 않습니다. 요약 결과의 기본 모양을 변경하려면 summaryFormatter
속성을 사용하여 형식을 지정할 수 있습니다.
public dateSummaryFormat(summary: IgxSummaryResult, summaryOperand : IgxSummaryOperand): string {
const result = summary.summaryResult;
if (summaryOperand instanceof IgxDateSummaryOperand && summary.key !== 'count'
&& result !== null && result !== undefined ) {
const pipe = new DatePipe('en-US' );
return pipe.transform(result,'MMM YYYY' );
}
return result;
}
typescript
<igx-column ... [summaryFormatter ]="dateSummaryFormat" > </igx-column >
html
import { DatePipe } from '@angular/common' ;
import { Component, OnInit, ViewChild } from '@angular/core' ;
import { IgxDateSummaryOperand, IgxGridComponent, IgxSummaryOperand, IgxSummaryResult, IgxColumnComponent, IgxCellTemplateDirective } from 'igniteui-angular' ;
import { DATA } from '../../data/nwindData' ;
import { IgxPreventDocumentScrollDirective } from '../../directives/prevent-scroll.directive' ;
@Component ({
selector : 'app-grid-summary-formatter' ,
styleUrls : ['./grid-summary-formatter.component.scss' ],
templateUrl : './grid-summary-formatter.component.html' ,
imports : [IgxGridComponent, IgxPreventDocumentScrollDirective, IgxColumnComponent, IgxCellTemplateDirective]
})
export class GridSummaryFormatterComponent implements OnInit {
@ViewChild ('grid1' , { read : IgxGridComponent, static : true })
public grid1: IgxGridComponent;
public data: any [];
public ngOnInit(): void {
this .data = DATA;
}
public dateSummaryFormat(summary: IgxSummaryResult, summaryOperand : IgxSummaryOperand): string {
const result = summary.summaryResult;
if (summaryOperand instanceof IgxDateSummaryOperand && summary.key !== 'count'
&& result !== null && result !== undefined ) {
const pipe = new DatePipe('en-US' );
return pipe.transform(result, 'MMM YYYY' );
}
return result;
}
}
ts コピー <div class ="grid__wrapper" >
<igx-grid [igxPreventDocumentScroll ]="true" #grid1 [data ]="data" [autoGenerate ]="false" height ="600px" width ="100%"
[allowFiltering ]='true' filterMode ="excelStyleFilter" >
<igx-column field ="ProductName" header ="Product Name" [sortable ]="true" [disableHiding ]="true" [dataType ]="'string'" >
</igx-column >
<igx-column field ="QuantityPerUnit" header ="Quantity Per Unit" [sortable ]="true" [disableHiding ]="true" [dataType ]="'string'" >
</igx-column >
<igx-column field ="UnitPrice" header ="Unit Price Category" [sortable ]="true" [disableHiding ]="true" dataType ="string" >
</igx-column >
<igx-column field ="OrderDate" header ="Order Date" [sortable ]="true" [disableHiding ]="true" [dataType ]="'date'" [hasSummary ]="true"
[summaryFormatter ]="dateSummaryFormat" >
</igx-column >
<igx-column field ="Discontinued" header ="Discontinued" [sortable ]="true" [disableHiding ]="true" [dataType ]="'boolean'" >
<ng-template igxCell let-cell ="cell" let-val >
@if (val) {
<img src ="https://www.infragistics.com/angular-demos-lob/assets/images/grid/active.png" title ="Continued" alt ="Continued" />
}
@if (!val) {
<img src ="https://www.infragistics.com/angular-demos-lob/assets/images/grid/expired.png" title ="Discontinued" alt ="Discontinued" />
}
</ng-template >
</igx-column >
</igx-grid >
</div >
html コピー .grid__wrapper {
margin : 16px ;
}
scss コピー
Summaries with Group By
열별로 그룹화한 경우 그리드를 사용하면 summaryCalculationMode
및 summaryPosition
속성을 사용하여 요약 위치와 계산 모드를 변경할 수 있습니다. 이 두 속성과 함께 IgxGrid는 참조하는 그룹 행이 축소될 때 요약 행이 계속 표시되는지 여부를 결정할 수 있는 showSummaryOnCollapse
속성을 노출합니다.
summaryCalculationMode
속성의 사용 가능한 값은 다음과 같습니다.
rootLevelOnly - 요약은 루트 수준에 대해서만 계산됩니다.
childLevelsOnly - 요약은 하위 수준에 대해서만 계산됩니다.
rootAndChildLevels - 루트 및 하위 수준 모두에 대한 요약이 계산됩니다. 이것이 기본값입니다.
summaryPosition
속성의 사용 가능한 값은 다음과 같습니다.
top - 요약 행은 그룹 기준 행 하위 항목 앞에 나타납니다.
하단 - 요약 행은 행 하위 그룹별로 표시됩니다. 이것이 기본값입니다.
showSummaryOnCollapse
속성은 부울입니다. 기본값은 false 로 설정됩니다. 즉, 그룹 행이 축소되면 요약 행이 숨겨집니다. 속성이 true 로 설정되면 그룹 행이 축소될 때 요약 행이 계속 표시됩니다.
Demo
import { Component, OnInit, ViewChild, ViewEncapsulation } from '@angular/core' ;
import { DefaultSortingStrategy, GridSelectionMode, GridSummaryCalculationMode, GridSummaryPosition, IgxGridComponent, IgxNumberSummaryOperand, IgxSummaryOperand, IgxSummaryResult, ISortingExpression, SortingDirection, IgxButtonGroupComponent, IgxSwitchComponent, IgxColumnComponent } from 'igniteui-angular' ;
import { INVOICE_DATA } from '../../data/invoiceData' ;
import { IgxPreventDocumentScrollDirective } from '../../directives/prevent-scroll.directive' ;
class AvgSummary {
public operate(data?: any []): IgxSummaryResult[] {
const result = [];
const avg = IgxNumberSummaryOperand.average(data);
result.push({
key : 'avg' ,
label : 'Average' ,
summaryResult : data.length ? '$' + avg.toFixed(2 ) : ''
});
return result;
}
}
class SumSummary {
public operate(data?: any []): IgxSummaryResult[] {
const result = [];
result.push({
key : 'sum' ,
label : 'Sum' ,
summaryResult : IgxNumberSummaryOperand.sum(data)
});
return result;
}
}
@Component ({
selector : 'app-grid-groupby-summary-sample' ,
styleUrls : ['./grid-groupby-summary-sample.component.scss' ],
templateUrl : './grid-groupby-summary-sample.component.html' ,
imports : [IgxButtonGroupComponent, IgxSwitchComponent, IgxGridComponent, IgxPreventDocumentScrollDirective, IgxColumnComponent]
})
export class GridGroupBySummarySampleComponent {
@ViewChild ('grid1' , { read : IgxGridComponent, static : true })
public grid1: IgxGridComponent;
public data;
public expr: ISortingExpression[];
public avgSummary = AvgSummary;
public sumSummary = SumSummary;
public summaryPositions;
public summaryPosition: GridSummaryPosition = GridSummaryPosition.bottom;
public summaryCalcModes;
public summaryCalculationMode: GridSummaryCalculationMode = GridSummaryCalculationMode.rootAndChildLevels;
public selectionMode: GridSelectionMode = 'multiple' ;
constructor ( ) {
this .data = INVOICE_DATA;
this .expr = [
{ dir : SortingDirection.Asc, fieldName : 'ShipCountry' , ignoreCase : false ,
strategy : DefaultSortingStrategy.instance() }
];
this .summaryPositions = [
{
label : GridSummaryPosition.top,
selected : this .summaryPosition === GridSummaryPosition.top,
togglable : true
},
{
label : GridSummaryPosition.bottom,
selected : this .summaryPosition === GridSummaryPosition.bottom,
togglable : true
}
];
this .summaryCalcModes = [
{
label : 'Root Level Only' ,
selected : this .summaryCalculationMode === GridSummaryCalculationMode.rootLevelOnly,
togglable : true ,
value : GridSummaryCalculationMode.rootLevelOnly
},
{
label : 'Child Levels Only' ,
selected : this .summaryCalculationMode === GridSummaryCalculationMode.childLevelsOnly,
togglable : true ,
value : GridSummaryCalculationMode.childLevelsOnly
},
{
label : 'Root And Child Levels' ,
selected : this .summaryCalculationMode === GridSummaryCalculationMode.rootAndChildLevels,
togglable : true ,
value : GridSummaryCalculationMode.rootAndChildLevels
}
];
}
public selectSummaryPosition (event ) {
this .summaryPosition = this .summaryPositions[event.index].label;
this .grid1.summaryPosition = this .summaryPosition;
}
public selectSummaryCalcMode (event ) {
this .summaryCalculationMode = this .summaryCalcModes[event.index].value;
this .grid1.summaryCalculationMode = this .summaryCalculationMode;
}
public toggle (event ) {
this .grid1.showSummaryOnCollapse = !this .grid1.showSummaryOnCollapse;
}
public formatDate (val: Date ) {
return new Intl .DateTimeFormat('en-US' ).format(val);
}
public formatCurrency (value: number ) {
return '$' + value.toFixed(2 );
}
public isDate (value: any ) {
if (value instanceof Date ) {
return true ;
} else {
return false ;
}
}
}
ts コピー
<div class ="summary-chooser" >
<igx-buttongroup [values ]="summaryCalcModes" (selected )="selectSummaryCalcMode($event)" > </igx-buttongroup >
</div >
<div class ="summary-chooser" >
<igx-buttongroup [values ]="summaryPositions" (selected )="selectSummaryPosition($event)" > </igx-buttongroup >
</div >
<div class ="summary-chooser" >
<igx-switch labelPosition ="before" [checked ]='grid1.showSummaryOnCollapse' (change )='toggle($event)' > Show summary row when group row is collapsed:</igx-switch >
</div >
<igx-grid [igxPreventDocumentScroll ]="true" #grid1 [data ]="data" [width ]="'100%'" [height ]="'540px'" [rowSelection ]="selectionMode" [groupingExpressions ]="expr" >
<igx-column field ="ShipCountry" header ="Ship Country" width ="200px" [groupable ]="true" >
</igx-column >
<igx-column field ="ShipCity" header ="Ship City" width ="250px" [groupable ]="true" >
</igx-column >
<igx-column field ="UnitPrice" header ="Unit Price" width ="150px" [formatter ]="formatCurrency" dataType ="number" [groupable ]="true" [hasSummary ]="true" [summaries ]="avgSummary" >
</igx-column >
<igx-column field ="Quantity" header ="Quantity" width ="150px" dataType ="number" [groupable ]="true" [hasSummary ]="true" [summaries ]="sumSummary" >
</igx-column >
</igx-grid >
html コピー :host {
display : block;
padding : 16px ;
}
.summary-chooser {
margin-bottom : 16px ;
}
igx-buttongroup{
display : block;
width : 600px ;
}
scss コピー
Exporting Summaries
이 있습니다 exportSummaries
옵션 IgxExcelExporterOptions
내보낸 데이터에 그리드 요약이 포함되어야 하는지 여부를 지정합니다. 기본 exportSummaries
가치는 거짓 .
IgxExcelExporterService
는 모든 열 유형에 대한 기본 요약을 동등한 Excel 기능으로 내보내므로 시트가 수정될 때 계속해서 제대로 작동합니다. 아래 예에서 직접 시도해 보세요.
import { Component, ViewChild } from '@angular/core' ;
import { ColumnType, IgxExcelExporterOptions, IgxExcelExporterService, IgxGridComponent, IgxNumberSummaryOperand, IgxSummaryResult, IgxButtonDirective, IgxColumnComponent, IgxCellTemplateDirective, IgxCellHeaderTemplateDirective, IgxIconComponent } from 'igniteui-angular' ;
import { DATA } from '../../data/nwindData' ;
import { IgxPreventDocumentScrollDirective } from '../../directives/prevent-scroll.directive' ;
import { DatePipe } from '@angular/common' ;
class MySummary {
public operate(data?: any []): IgxSummaryResult[] {
const result = new IgxNumberSummaryOperand().operate(data);
result.push({
key : 'test' ,
label : 'Test' ,
summaryResult : data.filter((rec ) => rec > 10 && rec < 30 ).length
});
return result;
}
}
@Component ({
selector : 'app-grid-summary-export' ,
styleUrls : ['./grid-summary-export.component.scss' ],
templateUrl : './grid-summary-export.component.html' ,
imports : [IgxButtonDirective, IgxGridComponent, IgxPreventDocumentScrollDirective, IgxColumnComponent, IgxCellTemplateDirective, IgxCellHeaderTemplateDirective, IgxIconComponent, DatePipe]
})
export class GridSummaryExportComponent {
@ViewChild ('grid' , { read : IgxGridComponent, static : true })
public grid: IgxGridComponent;
public mySummary = MySummary;
public data;
public productId = 0 ;
constructor (private excelExportService: IgxExcelExporterService ) {
this .data = DATA;
this .productId = DATA.length;
}
public toggleSummary (column: ColumnType ) {
column.hasSummary = !column.hasSummary;
}
public exportButtonHandler ( ) {
this .excelExportService.export(this .grid, new IgxExcelExporterOptions('ExportedFile' ));
}
}
ts コピー <div class ="grid__wrapper" >
<div class ="button-container" >
<button igxButton ="contained" (click )="exportButtonHandler()" > Export To Excel</button >
Press the button to export the Grid as a .xlsx file.
</div >
<igx-grid [igxPreventDocumentScroll ]="true" #grid [data ]="data" [autoGenerate ]="false" height ="650px" width ="100%" >
<igx-column #col field ="ProductID" header ="Product ID" [headerClasses ]="'prodId'" >
</igx-column >
<igx-column #col field ="ProductName" header ="Product Name" [headerClasses ]="'prodId'" [hasSummary ]="true" >
<ng-template igxCell let-cell ="cell" let-val >
{{val}}
</ng-template >
<ng-template igxHeader let-col >
<div class ="header-text" > {{col.field}}</div >
<igx-icon class ="header-icon" style.color ="{{ col.hasSummary ? '#e41c77' : '' }}" (click )="toggleSummary(col)" > functions</igx-icon >
</ng-template >
</igx-column >
<igx-column #col field ="UnitPrice" header ="Price" [filterable ]="false" [editable ]="true" dataType ="number"
[hasSummary ]="true" >
<ng-template igxCell let-cell ="cell" let-val let-row >
${{val}}
</ng-template >
<ng-template igxHeader let-col >
<div class ="header-text" > {{col.field}}</div >
<igx-icon class ="header-icon" style.color ="{{ col.hasSummary ? '#e41c77' : '' }}" (click )="toggleSummary(col)" > functions</igx-icon >
</ng-template >
</igx-column >
<igx-column #col field ="UnitsInStock" header ="Units In Stock" dataType ="number" [editable ]="true"
[hasSummary ]="false" [summaries ]="mySummary" >
<ng-template igxCell let-cell ="cell" let-val let-row >
{{val}}
</ng-template >
<ng-template igxHeader let-col >
<div class ="header-text" > {{col.field}}</div >
<igx-icon class ="header-icon" style.color ="{{ col.hasSummary ? '#e41c77' : '' }}" (click )="toggleSummary(col)" > functions</igx-icon >
</ng-template >
</igx-column >
<igx-column #col field ="Discontinued" header ="Discontinued" [hasSummary ]="true" [dataType ]="'boolean'" >
<ng-template igxCell let-cell ="cell" let-val >
@if (val) {
<img src ="https://www.infragistics.com/angular-demos-lob/assets/images/grid/active.png" title ="Continued" alt ="Continued" />
}
@if (!val) {
<img src ="https://www.infragistics.com/angular-demos-lob/assets/images/grid/expired.png" title ="Discontinued" alt ="Discontinued" />
}
</ng-template >
<ng-template igxHeader let-col >
<div class ="header-text" > {{col.field}}</div >
<igx-icon class ="header-icon" style.color ="{{ col.hasSummary ? '#e41c77' : '' }}" (click )="toggleSummary(col)" > functions</igx-icon >
</ng-template >
</igx-column >
<igx-column #col field ="OrderDate" [dataType ]="'date'" [hasSummary ]="true" >
<ng-template igxCell let-cell ="cell" let-val let-row >
{{ val | date: 'MMM d, yyyy' }}
</ng-template >
<ng-template igxHeader let-col >
<div class ="header-text" > {{col.field}}</div >
<igx-icon class ="header-icon" style.color ="{{ col.hasSummary ? '#e41c77' : '' }}" (click )="toggleSummary(col)" > functions</igx-icon >
</ng-template >
</igx-column >
</igx-grid >
</div >
html コピー .grid-controls {
display : flex;
flex-flow : column nowrap;
justify-content : space-between;
margin : 0 16px 24px ;
igx-switch {
margin-top : 24px ;
}
}
.grid__wrapper {
margin : 0 auto;
padding : 16px ;
}
.header {
height : 100% ;
}
:host ::ng-deep{
.igx-grid__th .title{
width: 100% ;
cursor : auto;
}
@media screen and (max-width : 677px ){
.header-icon {
padding-bottom : 17px ;
padding-top : 17px ;
font-size : 1.4em ;
width : 1.1em ;
height : 1.1em ;
float : right;
}
.header-text {
float :left ;
white-space : nowrap;
overflow : hidden;
text-overflow : ellipsis;
width : 50% ;
}
}
@media screen and (min-width : 677px ){
.header-icon {
padding-top : 17px ;
font-size : 1.4em ;
width : 1.1em ;
height : 1.1em ;
float : right;
}
.header-text {
float :left ;
white-space : nowrap;
overflow : hidden;
text-overflow : ellipsis;
width : 50% ;
}
}
@media screen and (min-width : 992px ){
.header-icon {
padding-top : 17px ;
font-size : 1.4em ;
width : 1.1em ;
height : 1.1em ;
float : right;
margin-right : 10px ;
cursor : pointer;
}
.header-text {
float :left ;
white-space : nowrap;
width : 50% ;
cursor : auto;
}
}
}
.button-container {
margin : 25px auto;
}
scss コピー
내보낸 파일에는 시트의 각 DataRecord
수준을 보유하는 숨겨진 열이 포함되어 있습니다. 이 수준은 요약 함수에 포함되어야 하는 셀을 필터링하기 위해 요약에서 사용됩니다.
아래 표에서 각 기본 요약에 해당하는 Excel 수식을 찾을 수 있습니다.
데이터 형식
기능
엑셀 기능
string
, boolean
세다
="카운트: "&COUNTIF(시작:끝, 레코드레벨)
number
, currency
, percent
세다
="카운트: "&COUNTIF(시작:끝, 레코드레벨)
분
="최소: "&MIN(IF(start:end=recordLevel, rangeStart:rangeEnd))
최대
="최대: "&MAX(IF(start:end=recordLevel, rangeStart:rangeEnd))
평균
="평균: "&AVERAGEIF(시작:끝, 기록 수준, rangeStart:rangeEnd)
합집합
="합계: "&SUMIF(start:end, RecordLevel, rangeStart:rangeEnd)
date
세다
="카운트: "&COUNTIF(시작:끝, 레코드레벨)
가장 빠른
="가장 빠른: "& TEXT(MIN(IF(start:end=recordLevel, rangeStart:rangeEnd)), format)
최신
="최신: "&TEXT(MAX(IF(start:end=recordLevel, rangeStart:rangeEnd)), 형식)
Known Limitations
한정
설명
사용자 정의 요약 내보내기
사용자 정의 요약은 Excel 함수 대신 문자열로 내보내집니다.
템플릿 요약 내보내기
템플릿 요약은 지원되지 않으며 기본 요약으로 내보내집니다.
Keyboard Navigation
요약 행은 다음 키보드 상호 작용을 통해 탐색할 수 있습니다.
UP - 한 셀 위로 이동합니다.
DOWN - 한 셀 아래로 이동합니다.
LEFT - 한 셀 왼쪽으로 이동합니다.
RIGHT - 한 셀 오른쪽으로 이동합니다.
CTRL + LEFT 또는 HOME - 가장 왼쪽 셀로 이동합니다.
CTRL + RIGHT 또는 END - 가장 오른쪽 셀로 이동합니다.
스타일링
정렬 동작 스타일 지정을 시작하려면 모든 테마 기능과 구성 요소 믹스인이 있는 index
파일을 가져와야 합니다.
@use "igniteui-angular/theming" as *;
scss
가장 간단한 접근 방식에 따라, 우리는 grid-summary-theme
확장하고 $background-color
, $focus-background-color
, $label-color
, $result-color
, $pinned-border-width
허용하는 새로운 테마를 만듭니다. $pinned-border-style
및 $pinned-border-color
매개변수.
$custom-theme : grid-summary-theme(
$background-color : #e0f3ff ,
$focus-background-color : rgba(#94d1f7 , .3 ),
$label-color : #e41c77 ,
$result-color : black,
$pinned-border-width : 2px ,
$pinned-border-style : dotted,
$pinned-border-color : #e41c77
);
scss
우리가 방금 한 것처럼 색상 값을 하드 코딩하는 대신, and color
함수를 사용하여 palette
색상 측면에서 더 큰 유연성을 얻을 수 있습니다. 사용 방법에 대한 자세한 지침은 항목을 참조하십시오 Palettes
.
마지막 단계는 구성 요소 사용자 지정 테마를 포함하는 것입니다.
@include css-vars($custom-theme );
scss
구성 요소가 Emulated
ViewEncapsulation을 사용하는 경우::ng-deep
사용하여 이 캡슐화를 penetrate
해야 합니다.
:host {
::ng-deep {
@include css-vars($custom-theme );
}
}
scss
Demo
import { Component, OnInit, ViewChild, ViewEncapsulation } from '@angular/core' ;
import { DefaultSortingStrategy, GridSelectionMode, GridSummaryCalculationMode, GridSummaryPosition, IgxGridComponent, IgxNumberSummaryOperand, IgxSummaryOperand, IgxSummaryResult, ISortingExpression, SortingDirection, IgxButtonGroupComponent, IgxGridToolbarComponent, IgxGridToolbarActionsComponent, IgxGridToolbarPinningComponent, IgxColumnComponent } from 'igniteui-angular' ;
import { INVOICE_DATA } from '../../data/invoiceData' ;
import { IgxPreventDocumentScrollDirective } from '../../directives/prevent-scroll.directive' ;
class CustomSummary {
public operate(data?: any []): IgxSummaryResult[] {
const result = [];
result.push({
key : 'sum' ,
label : 'Sum' ,
summaryResult : IgxNumberSummaryOperand.sum(data)
}, {
key : 'count' ,
label : 'Count' ,
summaryResult : data.length ? data.length : 0
});
return result;
}
}
@Component ({
selector : 'app-grid-groupby-summary-sample' ,
styleUrls : ['./grid-groupby-summary-styling-sample.component.scss' ],
templateUrl : './grid-groupby-summary-styling-sample.component.html' ,
imports : [IgxButtonGroupComponent, IgxGridComponent, IgxPreventDocumentScrollDirective, IgxGridToolbarComponent, IgxGridToolbarActionsComponent, IgxGridToolbarPinningComponent, IgxColumnComponent]
})
export class GridGroupBySummaryStylingSampleComponent {
@ViewChild ('grid1' , { read : IgxGridComponent, static : true })
public grid1: IgxGridComponent;
public data;
public expr: ISortingExpression[];
public customSummary = CustomSummary;
public summaryPositions;
public summaryPosition: GridSummaryPosition = GridSummaryPosition.bottom;
public summaryCalcModes;
public summaryCalculationMode: GridSummaryCalculationMode = GridSummaryCalculationMode.rootAndChildLevels;
public selectionMode: GridSelectionMode = 'multiple' ;
constructor ( ) {
this .data = INVOICE_DATA;
this .expr = [
{ dir : SortingDirection.Asc, fieldName : 'ShipCountry' , ignoreCase : false ,
strategy : DefaultSortingStrategy.instance() }
];
this .summaryPositions = [
{
label : GridSummaryPosition.top,
selected : this .summaryPosition === GridSummaryPosition.top,
togglable : true
},
{
label : GridSummaryPosition.bottom,
selected : this .summaryPosition === GridSummaryPosition.bottom,
togglable : true
}
];
this .summaryCalcModes = [
{
label : 'Root Level Only' ,
selected : this .summaryCalculationMode === GridSummaryCalculationMode.rootLevelOnly,
togglable : true ,
value : GridSummaryCalculationMode.rootLevelOnly
},
{
label : 'Child Levels Only' ,
selected : this .summaryCalculationMode === GridSummaryCalculationMode.childLevelsOnly,
togglable : true ,
value : GridSummaryCalculationMode.childLevelsOnly
},
{
label : 'Root And Child Levels' ,
selected : this .summaryCalculationMode === GridSummaryCalculationMode.rootAndChildLevels,
togglable : true ,
value : GridSummaryCalculationMode.rootAndChildLevels
}
];
}
public selectSummaryPosition (event ) {
this .summaryPosition = this .summaryPositions[event.index].label;
this .grid1.summaryPosition = this .summaryPosition;
}
public selectSummaryCalcMode (event ) {
this .summaryCalculationMode = this .summaryCalcModes[event.index].value;
this .grid1.summaryCalculationMode = this .summaryCalculationMode;
}
public formatDate (val: Date ) {
return new Intl .DateTimeFormat('en-US' ).format(val);
}
public formatCurrency (value: number ) {
return '$' + value.toFixed(2 );
}
public isDate (value: any ) {
if (value instanceof Date ) {
return true ;
} else {
return false ;
}
}
}
ts コピー <div class ="grid-wrapper" >
<div class ="summary-chooser" >
<igx-buttongroup [values ]="summaryCalcModes" (selected )="selectSummaryCalcMode($event)" > </igx-buttongroup >
</div >
<div class ="summary-chooser" >
<igx-buttongroup [values ]="summaryPositions" (selected )="selectSummaryPosition($event)" > </igx-buttongroup >
</div >
<igx-grid [igxPreventDocumentScroll ]="true" #grid1 [data ]="data" [width ]="'100%'" [height ]="'570px'" [rowSelection ]='selectionMode' [groupingExpressions ]='expr' >
<igx-grid-toolbar >
<igx-grid-toolbar-actions >
<igx-grid-toolbar-pinning > </igx-grid-toolbar-pinning >
</igx-grid-toolbar-actions >
</igx-grid-toolbar >
<igx-column field ="ShipCountry" header ="Ship Country" width ="200px" [groupable ]="true" [pinned ]="true" >
</igx-column >
<igx-column field ="ShipCity" header ="Ship City" width ="250px" [groupable ]="true" >
</igx-column >
<igx-column field ="UnitPrice" header ="Unit Price" width ="150px" [formatter ]="formatCurrency" dataType ="number" [groupable ]="true" [hasSummary ]="true" >
</igx-column >
<igx-column field ="Quantity" header ="Quantity" width ="150px" dataType ="number" [groupable ]="true" [hasSummary ]="true" [summaries ]="customSummary" >
</igx-column >
</igx-grid >
</div >
html コピー @use "layout.scss" ;
@use "igniteui-angular/theming" as *;
$summaries-background : #e0f3ff ;
$custom-theme : grid-summary-theme(
$background-color : $summaries-background ,
$focus-background-color : rgba(#94d1f7 , 0.3 ),
$label-color : #e41c77 ,
$result-color : black,
$pinned-border-width : 2px ,
$pinned-border-style : dotted,
$pinned-border-color : #e41c77 ,
);
:host {
::ng-deep {
igx-grid-summary-row {
--summaries-patch-background: #{$summaries-background };
}
@include css-vars($custom-theme );
}
}
scss コピー
API References
Additional Resources
우리 커뮤니티는 활동적이며 항상 새로운 아이디어를 환영합니다.