Angular Tree Grid Sorting
Ignite UI for Angular에서 데이터 정렬은 열 단위로 활성화되어 igx-tree-grid에 정렬 가능한 열과 정렬 불가능한 열이 혼합될 수 있습니다. 각도 정렬 작업을 수행하면 지정된 기준에 따라 레코드의 표시 순서를 변경할 수 있습니다.
Note
지금까지는 그룹화/정렬이 서로 함께 작동했습니다. 13.2 버전에서는 정렬에서 그룹화를 분리하는 새로운 동작이 도입되었습니다. 예를 들어 그룹화를 지우면 그리드의 정렬 표현식이 지워지지 않으며 그 반대의 경우도 마찬가지입니다. 그러나 열이 정렬되고 그룹화된 경우 그룹화된 식이 우선합니다.
Angular Tree Grid Sorting Overview Example
또한 igx-tree-grid의 출력을 사용하여 정렬하기 위해 사용자 정의 컨텍스트 메뉴가 contextMenu
추가되었습니다.
이는 sortable
입력을 통해 수행됩니다. 트리 그리드 정렬을 사용하면 sortingIgnoreCase
속성을 설정하여 대소문자 구분 정렬을 수행할 수도 있습니다.
<igx-column field="Name" header="Order Product" [dataType]="'string'" sortable="true"></igx-column>
Sorting Indicators
정렬된 순서가 표시되지 않으면 일정량의 열이 정렬되어 있으면 정말 혼란스러울 수 있습니다.
IgxTreeGrid는 정렬된 각 열의 인덱스를 표시하여 이 문제에 대한 솔루션을 제공합니다.
Sorting through the API
Tree Grid sort
방법을 사용하여 Tree Grid API를 통해 모든 열 또는 열 조합을 정렬할 수 있습니다.
import { SortingDirection } from 'igniteui-angular';
// import { SortingDirection } from '@infragistics/igniteui-angular'; for licensed package
// Perform a case insensitive ascending sort on the ProductName column.
this.treeGrid.sort({ fieldName: 'Name', dir: SortingDirection.Asc, ignoreCase: true });
// Perform sorting on both the ProductName and Price columns.
this.treeGrid.sort([
{ fieldName: 'Name', dir: SortingDirection.Asc, ignoreCase: true },
{ fieldName: 'UnitPrice', dir: SortingDirection.Desc }
]);
Note
정렬은 DefaultSortingStrategy
알고리즘을 사용하여 수행됩니다. 모든 IgxColumnComponent
또는 ISortingExpression
ISortingStrategy
의 사용자 정의 구현을 대체 알고리즘으로 사용할 수 있습니다. 이는 예를 들어 복잡한 템플릿 열이나 이미지 열에 대해 사용자 정의 정렬을 정의해야 할 때 유용합니다.
필터링 동작과 마찬가지로 clearSort
메서드를 사용하여 정렬 상태를 지울 수 있습니다.
// Removes the sorting state from the ProductName column
this.treeGrid.clearSort('Name');
// Removes the sorting state from every column in the Tree Grid
this.treeGrid.clearSort();
Note
그만큼 sortStrategy
~의 트리 그리드에 비해 종류가 다릅니다. sortStrategy
~의 열, 서로 다른 범위에서 작동하고 서로 다른 매개변수를 노출하기 때문입니다.
Note
정렬 작업은 트리 그리드의 기본 데이터 소스를 변경 하지 않습니다.
Initial sorting state
정렬 표현식의 배열을 트리 그리드의 sortingExpressions
속성에 전달하여 트리 그리드의 초기 정렬 상태를 설정할 수 있습니다.
public ngAfterViewInit(): void {
this.treeGrid.sortingExpressions = [
{
dir: SortingDirection.Asc, fieldName: 'UnitPrice',
ignoreCase: true, strategy: DefaultSortingStrategy.instance()
}
];
}
Note
string
유형의 값이 dataType
Date
열에서 사용되는 경우 트리 그리드는 해당 값을 Date
객체로 구문 분석하지 않으며 트리 그리드 sorting
사용하면 예상대로 작동하지 않습니다. string
객체를 사용하려면 값을 Date
객체로 구문 분석하기 위해 애플리케이션 수준에서 추가 논리를 구현해야 합니다.
Sorting Indicators Templates
열 머리글의 정렬 표시기 아이콘은 템플릿을 사용하여 사용자 정의할 수 있습니다. 모든 정렬 상태(오름차순, 내림차순, 없음)에 대한 정렬 표시기 템플릿을 작성하는 데 다음 지시문을 사용할 수 있습니다.
IgxSortHeaderIconDirective
– 정렬이 적용되지 않은 경우 정렬 아이콘의 템플릿을 다시 지정합니다.
<ng-template igxSortHeaderIcon>
<igx-icon>unfold_more</igx-icon>
</ng-template>
IgxSortAscendingHeaderIconDirective
– 열이 오름차순으로 정렬될 때 정렬 아이콘의 템플릿을 다시 지정합니다.
<ng-template igxSortAscendingHeaderIcon>
<igx-icon>expand_less</igx-icon>
</ng-template>
IgxSortDescendningHeaderIconDirective
– 열이 내림차순으로 정렬될 때 정렬 아이콘의 템플릿을 다시 지정합니다.
<ng-template igxSortDescendingHeaderIcon>
<igx-icon>expand_more</igx-icon>
</ng-template>
스타일링
정렬 동작 스타일 지정을 시작하려면 모든 테마 기능과 구성 요소 믹스인이 있는 index
파일을 가져와야 합니다.
@use "igniteui-angular/theming" as *;
// IMPORTANT: Prior to Ignite UI for Angular version 13 use:
// @import '~igniteui-angular/lib/core/styles/themes/index';
가장 간단한 접근 방식에 따라 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
);
Note
우리가 방금 한 것처럼 색상 값을 하드 코딩하는 대신, and color
함수를 사용하여 palette
색상 측면에서 더 큰 유연성을 얻을 수 있습니다. 사용 방법에 대한 자세한 지침은 항목을 참조하십시오 Palettes
.
마지막 단계는 구성요소 믹스인을 포함하는 것입니다.
@include css-vars($custom-theme);
Demo
Note
샘플은 Change Theme
에서 선택한 전역 테마의 영향을 받지 않습니다.