Angular 계층적 그리드 정렬
Ignite UI for Angular Hierarchical Grid에서 데이터 정렬은 열 단위로 활성화되어 igx-hierarchical-grid에 정렬 가능한 열과 정렬 불가능한 열이 혼합될 수 있습니다. 각도 정렬 작업을 수행하면 지정된 기준에 따라 레코드의 표시 순서를 변경할 수 있습니다.
지금까지는 그룹화/정렬이 서로 함께 작동했습니다. 13.2 버전에서는 정렬에서 그룹화를 분리하는 새로운 동작이 도입되었습니다. 예를 들어 그룹화를 지우면 그리드의 정렬 표현식이 지워지지 않으며 그 반대의 경우도 마찬가지입니다. 그러나 열이 정렬되고 그룹화된 경우 그룹화된 식이 우선합니다.
Angular 계층적 그리드 정렬 개요 예
또한 igx-hierarchical-grid contextMenu
의 출력을 사용하여 정렬하기 위해 사용자 정의 컨텍스트 메뉴가 추가되었습니다.
import { AfterViewInit, Component, OnInit, ViewChild } from '@angular/core' ;
import { DefaultSortingStrategy, IgxHierarchicalGridComponent, IgxRowIslandComponent, SortingDirection, IgxColumnComponent, IgxCellTemplateDirective } from 'igniteui-angular' ;
import { SINGERS } from '../../data/singersData' ;
import { IgxPreventDocumentScrollDirective } from '../../directives/prevent-scroll.directive' ;
import { NgIf } from '@angular/common' ;
import { HGridContextmenuComponent } from '.hgrid-contextmenu/hgrid-contextmenu.component' ;
@Component ({
selector : 'app-hierarchical-grid-sorting' ,
styleUrls : ['./hierarchical-grid-sorting.component.scss' ],
templateUrl : 'hierarchical-grid-sorting.component.html' ,
imports : [IgxHierarchicalGridComponent, IgxPreventDocumentScrollDirective, IgxColumnComponent, IgxCellTemplateDirective, IgxRowIslandComponent, NgIf, HGridContextmenuComponent]
})
export class HGridSortingSampleComponent implements OnInit , AfterViewInit {
@ViewChild ('hierarchicalGrid' , { static : true })
private hierarchicalGrid: IgxHierarchicalGridComponent;
public localdata;
public contextmenu = false ;
public contextmenuX = 0 ;
public contextmenuY = 0 ;
public clickedCell = null ;
constructor ( ) {}
public ngOnInit(): void {
this .localdata = SINGERS;
this .hierarchicalGrid.sortingExpressions = [
{ dir : SortingDirection.Asc, fieldName : 'Artist' ,
ignoreCase : true , strategy : DefaultSortingStrategy.instance() }
];
}
public ngAfterViewInit(): void {
this .hierarchicalGrid.cdr.detectChanges();
}
public rightClick (eventArgs ) {
eventArgs.event.preventDefault();
this .contextmenuX = eventArgs.event.clientX;
this .contextmenuY = eventArgs.event.clientY;
this .contextmenu = true ;
this .clickedCell = eventArgs.cell;
}
public disableContextMenu ( ) {
this .contextmenu = false ;
}
public formatter = (a ) => a;
}
ts コピー <div class ="hgrid-sample" (window:click )="disableContextMenu()" >
<igx-hierarchical-grid [igxPreventDocumentScroll ]="true" class ="hgrid" [data ]="localdata" [autoGenerate ]="false"
[height ]="'480px'" [width ]="'100%'" [rowHeight ]="'65px'" (contextMenu )="rightClick($event)" #hierarchicalGrid >
<igx-column field ="Artist" [sortable ]="true" > </igx-column >
<igx-column field ="Photo" >
<ng-template igxCell let-cell ="cell" >
<div class ="cell__inner_2" >
<img [src ]="cell.value" class ="photo" />
</div >
</ng-template >
</igx-column >
<igx-column field ="Debut" [sortable ]="true" [formatter ]="formatter" > </igx-column >
<igx-column field ="GrammyNominations" header ="Grammy Nominations" [sortable ]="true" > </igx-column >
<igx-column field ="GrammyAwards" header ="Grammy Awards" [sortable ]="true" > </igx-column >
<igx-row-island [height ]="null" [key ]="'Albums'" [autoGenerate ]="false" >
<igx-column field ="Album" [sortable ]="true" > </igx-column >
<igx-column field ="LaunchDate" header ="Launch Date" [sortable ]="true" [dataType ]="'date'" > </igx-column >
<igx-column field ="BillboardReview" header ="Billboard Review" [sortable ]="true" > </igx-column >
<igx-column field ="USBillboard200" header ="US Billboard 200" [sortable ]="true" > </igx-column >
<igx-row-island [height ]="null" [key ]="'Songs'" [autoGenerate ]="false" >
<igx-column field ="Number" header ="No." [sortable ]="true" > </igx-column >
<igx-column field ="Title" [sortable ]="true" > </igx-column >
<igx-column field ="Released" dataType ="date" [sortable ]="true" > </igx-column >
<igx-column field ="Genre" [sortable ]="true" > </igx-column >
</igx-row-island >
</igx-row-island >
<igx-row-island [height ]="null" [key ]="'Tours'" [autoGenerate ]="false" >
<igx-column field ="Tour" [sortable ]="true" > </igx-column >
<igx-column field ="StartedOn" header ="Started on" [sortable ]="true" > </igx-column >
<igx-column field ="Location" [sortable ]="true" > </igx-column >
<igx-column field ="Headliner" [sortable ]="true" > </igx-column >
</igx-row-island >
</igx-hierarchical-grid >
<div *ngIf ="contextmenu" >
<app-hgrid-contextmenu [x ]="contextmenuX" [y ]="contextmenuY" [cell ]="clickedCell" > </app-hgrid-contextmenu >
</div >
</div >
html コピー .photo {
vertical-align : middle;
max-height : 62px ;
}
.cell__inner_2 {
margin : 1px
}
.hgrid-sample{
padding: 16px ;
}
scss コピー
이 샘플이 마음에 드시나요? 전체 Ignite UI for Angular 툴킷에 액세스하고 몇 분 안에 나만의 앱을 구축해 보세요. 무료로 다운로드하세요.
이는 sortable
입력을 통해 수행됩니다. 계층적 그리드 정렬을 사용하면 sortingIgnoreCase
속성을 설정하여 대소문자 구분 정렬을 수행할 수도 있습니다.
<igx-column field ="ProductName" header ="Product Name" [dataType ]="'string'" sortable ="true" > </igx-column >
html
지표 정렬
정렬된 순서가 표시되지 않으면 일정량의 열이 정렬되어 있으면 정말 혼란스러울 수 있습니다.
IgxHierarchicalGrid 는 정렬된 각 열의 인덱스를 표시하여 이 문제에 대한 솔루션을 제공합니다.
API를 통한 정렬
Hierarchical Grid sort
방법을 사용하여 Hierarchical Grid API를 통해 모든 열 또는 열 조합을 정렬할 수 있습니다.
import { SortingDirection } from 'igniteui-angular' ;
this .hierarchicalGrid.sort({ fieldName : 'ProductName' , dir : SortingDirection.Asc, ignoreCase : true });
this .hierarchicalGrid.sort([
{ fieldName : 'ProductName' , dir : SortingDirection.Asc, ignoreCase : true },
{ fieldName : 'Price' , dir : SortingDirection.Desc }
]);
typescript
필터링 동작과 마찬가지로 clearSort
메서드를 사용하여 정렬 상태를 지울 수 있습니다.
this .hierarchicalGrid.clearSort('ProductName' );
this .hierarchicalGrid.clearSort();
typescript
정렬 작업은 계층적 그리드의 기본 데이터 소스를 변경 하지 않습니다 .
초기 정렬 상태
계층적 격자의 sortingExpressions
속성에 정렬 표현식의 배열을 전달하여 계층적 격자의 초기 정렬 상태를 설정할 수 있습니다.
public ngOnInit(): void {
this .hierarchicalGrid.sortingExpressions = [
{
dir : SortingDirection.Asc, fieldName : 'Artist' ,
ignoreCase : true , strategy : DefaultSortingStrategy.instance()
}
];
}
typescript
string
유형의 값이 dataType
Date
열에서 사용되는 경우 계층적 그리드는 해당 값을 Date
객체로 구문 분석하지 않으며 계층적 그리드 sorting
사용하면 예상대로 작동하지 않습니다. string
객체를 사용하려면 값을 Date
객체로 구문 분석하기 위해 애플리케이션 수준에서 추가 논리를 구현해야 합니다.
지표 템플릿 정렬
열 머리글의 정렬 표시기 아이콘은 템플릿을 사용하여 사용자 정의할 수 있습니다. 모든 정렬 상태(오름차순, 내림차순, 없음)에 대한 정렬 표시기 템플릿을 작성하는 데 다음 지시문을 사용할 수 있습니다.
IgxSortHeaderIconDirective
– 정렬이 적용되지 않은 경우 정렬 아이콘의 템플릿을 다시 지정합니다.
<ng-template igxSortHeaderIcon >
<igx-icon > unfold_more</igx-icon >
</ng-template >
html
IgxSortAscendingHeaderIconDirective
– 열이 오름차순으로 정렬될 때 정렬 아이콘의 템플릿을 다시 지정합니다.
<ng-template igxSortAscendingHeaderIcon >
<igx-icon > expand_less</igx-icon >
</ng-template >
html
IgxSortDescendningHeaderIconDirective
– 열이 내림차순으로 정렬될 때 정렬 아이콘의 템플릿을 다시 지정합니다.
<ng-template igxSortDescendingHeaderIcon >
<igx-icon > expand_more</igx-icon >
</ng-template >
html
스타일링
정렬 동작 스타일 지정을 시작하려면 모든 테마 기능과 구성 요소 믹스인이 있는 index
파일을 가져와야 합니다.
@use "igniteui-angular/theming" as *;
scss
가장 간단한 접근 방식에 따라 grid-theme
확장하고 $sorted-header-icon-color
및 sortable-header-icon-hover-color
매개 변수를 허용하는 새로운 테마를 만듭니다.
$custom-theme : grid-theme(
$sorted-header-icon-color : #ffb06a ,
$sortable-header-icon-hover-color : black
);
scss
우리가 방금 한 것처럼 색상 값을 하드 코딩하는 대신, and color
함수를 사용하여 palette
색상 측면에서 더 큰 유연성을 얻을 수 있습니다. 사용 방법에 대한 자세한 지침은 항목을 참조하십시오 Palettes
.
마지막 단계는 구성요소 믹스인을 포함하는 것입니다.
@include css-vars($custom-theme );
scss
데모
import { AfterViewInit, Component, OnInit, ViewChild } from '@angular/core' ;
import { DefaultSortingStrategy, IgxHierarchicalGridComponent, SortingDirection, IgxColumnComponent, IgxCellTemplateDirective, IgxRowIslandComponent } from 'igniteui-angular' ;
import { SINGERS } from '../../data/singersData' ;
import { IgxPreventDocumentScrollDirective } from '../../directives/prevent-scroll.directive' ;
@Component ({
selector : 'app-hierarchical-grid-sorting-styling' ,
styleUrls : ['./hierarchical-grid-sorting-styling.component.scss' ],
templateUrl : 'hierarchical-grid-sorting-styling.component.html' ,
imports : [IgxHierarchicalGridComponent, IgxPreventDocumentScrollDirective, IgxColumnComponent, IgxCellTemplateDirective, IgxRowIslandComponent]
})
export class HGridSortingStylingComponent implements OnInit , AfterViewInit {
@ViewChild ('hierarchicalGrid' , { static : true })
private hierarchicalGrid: IgxHierarchicalGridComponent;
public localdata;
constructor ( ) {}
public ngOnInit(): void {
this .localdata = SINGERS;
this .hierarchicalGrid.sortingExpressions = [
{ dir : SortingDirection.Asc, fieldName : 'Artist' ,
ignoreCase : true , strategy : DefaultSortingStrategy.instance() }
];
}
public ngAfterViewInit(): void {
this .hierarchicalGrid.cdr.detectChanges();
}
public formatter = (a ) => a;
}
ts コピー <div class ="hgrid-sample" >
<igx-hierarchical-grid [igxPreventDocumentScroll ]="true" class ="hgrid" [data ]="localdata" [autoGenerate ]="false" [height ]="'480px'" [width ]="'100%'"
[rowHeight ]="'65px'" #hierarchicalGrid >
<igx-column field ="Artist" [sortable ]="true" > </igx-column >
<igx-column field ="Photo" >
<ng-template igxCell let-cell ="cell" >
<div class ="cell__inner_2" >
<img [src ]="cell.value" class ="photo" />
</div >
</ng-template >
</igx-column >
<igx-column field ="Debut" [sortable ]="true" [formatter ]="formatter" > </igx-column >
<igx-column field ="GrammyNominations" header ="Grammy Nominations" [sortable ]="true" > </igx-column >
<igx-column field ="GrammyAwards" header ="Grammy Awards" [sortable ]="true" > </igx-column >
<igx-row-island [height ]="null" [key ]="'Albums'" [autoGenerate ]="false" >
<igx-column field ="Album" [sortable ]="true" > </igx-column >
<igx-column field ="LaunchDate" header ="Launch Date" [sortable ]="true" [dataType ]="'date'" > </igx-column >
<igx-column field ="BillboardReview" header ="Billboard Review" [sortable ]="true" > </igx-column >
<igx-column field ="USBillboard200" header ="US Billboard 200" [sortable ]="true" > </igx-column >
<igx-row-island [height ]="null" [key ]="'Songs'" [autoGenerate ]="false" >
<igx-column field ="Number" header ="No." [sortable ]="true" > </igx-column >
<igx-column field ="Title" [sortable ]="true" > </igx-column >
<igx-column field ="Released" dataType ="date" [sortable ]="true" > </igx-column >
<igx-column field ="Genre" [sortable ]="true" > </igx-column >
</igx-row-island >
</igx-row-island >
<igx-row-island [height ]="null" [key ]="'Tours'" [autoGenerate ]="false" >
<igx-column field ="Tour" [sortable ]="true" > </igx-column >
<igx-column field ="StartedOn" header ="Started on" [sortable ]="true" > </igx-column >
<igx-column field ="Location" [sortable ]="true" > </igx-column >
<igx-column field ="Headliner" [sortable ]="true" > </igx-column >
</igx-row-island >
</igx-hierarchical-grid >
</div >
html コピー @use "layout.scss" ;
@use "igniteui-angular/theming" as *;
$custom-theme : grid-theme(
$sorted-header-icon-color : #ffb06a ,
$sortable-header-icon-hover-color : black
);
:host ::ng-deep {
@include css-vars($custom-theme );
}
scss コピー
샘플은 Change Theme
에서 선택한 전역 테마의 영향을 받지 않습니다.
API 참조
추가 리소스
우리 커뮤니티는 활동적이며 항상 새로운 아이디어를 환영합니다.