Angular Tree Grid Sorting
Ignite UI for Angular에서 데이터 정렬은 열 단위로 활성화되어 igx-tree-grid에 정렬 가능한 열과 정렬 불가능한 열이 혼합될 수 있습니다. 각도 정렬 작업을 수행하면 지정된 기준에 따라 레코드의 표시 순서를 변경할 수 있습니다.
Note
지금까지는 그룹화/정렬이 서로 함께 작동했습니다. 13.2 버전에서는 정렬에서 그룹화를 분리하는 새로운 동작이 도입되었습니다. 예를 들어 그룹화를 지우면 그리드의 정렬 표현식이 지워지지 않으며 그 반대의 경우도 마찬가지입니다. 그러나 열이 정렬되고 그룹화된 경우 그룹화된 식이 우선합니다.
Angular Tree Grid Sorting Overview Example
Additionally there is a custom context menu added for sorting using igx-tree-grid's contextMenu Output.
This is done via the sortable input. With the Tree Grid sorting, you can also set the sortingIgnoreCase property to perform case sensitive sorting:
<igx-column field="Name" header="Order Product" [dataType]="'string'" sortable="true"></igx-column>
Sorting Indicators
정렬된 순서가 표시되지 않으면 일정량의 열이 정렬되어 있으면 정말 혼란스러울 수 있습니다.
IgxTreeGrid는 정렬된 각 열의 인덱스를 표시하여 이 문제에 대한 솔루션을 제공합니다.
Sorting through the API
You can sort any column or a combination of columns through the Tree Grid API using the Tree Grid sort method:
import { SortingDirection } from 'igniteui-angular/grids/core';
// 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 알고리즘을 사용해 수행됩니다. 또는IgxColumnComponentISortingExpression 대체 알고리즘의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
The sortStrategy of the Tree Grid is of different type compared to the sortStrategy of the column, since they work in different scopes and expose different parameters.
Note
정렬 작업은 트리 그리드의 기본 데이터 소스를 변경 하지 않습니다.
Initial sorting state
It is possible to set the initial sorting state of the Tree Grid by passing an array of sorting expressions to the sortingExpressions property of the Tree Grid.
public ngAfterViewInit(): void {
this.treeGrid.sortingExpressions = [
{
dir: SortingDirection.Asc, fieldName: 'UnitPrice',
ignoreCase: true, strategy: DefaultSortingStrategy.instance()
}
];
}
Note
If values of type string are used by a column of dataType Date, the Tree Grid won't parse them to Date objects and using Tree Grid sorting won't work as expected. If you want to use string objects, additional logic should be implemented on an application level, in order to parse the values to Date objects.
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
우리가 방금 한 것처럼 색상 값을 하드코딩하는 대신, andpalette 함수를 사용color 해 색상 측면에서 더 큰 유연성을 얻을 수 있습니다. 사용 방법에 대한 자세한 안내는 해당 주제를 참고Palettes 해 주세요.
마지막 단계는 구성요소 믹스인을 포함하는 것입니다.
@include css-vars($custom-theme);
Demo
Note
샘플은 선택된 글로벌 테마Change Theme의 영향을 받지 않습니다.