Angular 그리드 정렬

    Ignite UI for Angular 에서는 데이터 정렬이 열별 수준에서 활성화됩니다. 즉, igx-grid에는 정렬 가능한 열과 정렬 불가능한 열이 혼합되어 있을 수 있습니다. 각도 정렬 작업을 수행하면 지정된 기준에 따라 레코드의 표시 순서를 변경할 수 있습니다.

    Note

    지금까지는 그룹화/정렬이 서로 결합되어 작동했습니다. 13.2 버전에서는 그룹화와 정렬을 분리하는 새로운 동작이 도입되었습니다. 예를 들어 그룹화를 지워도 그리드의 정렬 표현식은 지워지지 않으며 그 반대의 경우도 마찬가지입니다. 그러나 열이 정렬되고 그룹화되는 경우에는 그룹화된 표현식이 우선 적용됩니다.

    Angular Grid Sorting Overview Example

    이는 sortable 입력을 통해 수행됩니다. 그리드 정렬을 사용하면 sortingIgnoreCase 속성을 설정하여 대소문자 구분 정렬을 수행할 수도 있습니다.

    <igx-column field="ProductName" header="Product Name" [dataType]="'string'" sortable="true"></igx-column>
    

    Sorting Indicators

    정렬된 순서가 표시되지 않으면 일정량의 열이 정렬되어 있으면 정말 혼란스러울 수 있습니다.

    IgxGrid는 정렬된 각 열의 인덱스를 표시하여 이 문제에 대한 솔루션을 제공합니다.

    Sorting through the API

    Grid sort 방법을 사용하여 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.grid.sort({ fieldName: 'ProductName', dir: SortingDirection.Asc, ignoreCase: true });
    
    // Perform sorting on both the ProductName and Price columns.
    this.grid.sort([
        { fieldName: 'ProductName', dir: SortingDirection.Asc, ignoreCase: true },
        { fieldName: 'Price', dir: SortingDirection.Desc }
    ]);
    
    Note

    정렬은 DefaultSortingStrategy 알고리즘을 사용하여 수행됩니다. 모든 IgxColumnComponent 또는 ISortingExpression​ ​ISortingStrategy의 사용자 정의 구현을 대체 알고리즘으로 사용할 수 있습니다. 이는 예를 들어 복잡한 템플릿 열이나 이미지 열에 대해 사용자 정의 정렬을 정의해야 할 때 유용합니다.

    필터링 동작과 마찬가지로 clearSort 메서드를 사용하여 정렬 상태를 지울 수 있습니다.

    // Removes the sorting state from the ProductName column
    this.grid.clearSort('ProductName');
    
    // Removes the sorting state from every column in the Grid
    this.grid.clearSort();
    
    Note

    그만큼 sortStrategy ~의 그리드에 비해 종류가 다릅니다. sortStrategy ~의 , 서로 다른 범위에서 작동하고 서로 다른 매개변수를 노출하기 때문입니다.

    Note

    정렬 작업은 그리드의 기본 데이터 소스를 변경 하지 않습니다.

    Initial sorting state

    정렬 표현식의 배열을 Grid의 sortingExpressions 속성에 전달하여 Grid의 초기 정렬 상태를 설정할 수 있습니다.

    public ngOnInit() {
        this.grid.sortingExpressions = [
            { fieldName: 'Name', dir: SortingDirection.Asc, ignoreCase: true },
            { fieldName: 'Price', dir: SortingDirection.Desc }
        ];
    }
    
    public ngOnInit() {
        this.grid.sortingExpressions = [
            { fieldName: 'ProductName', dir: SortingDirection.Asc, ignoreCase: true },
            { fieldName: 'Price', dir: SortingDirection.Desc }
        ];
    }
    
    Note

    string 유형의 값이 dataType Date 열에서 사용되는 경우 Grid는 해당 값을 Date 객체로 구문 분석하지 않으며 Grid sorting 사용하면 예상대로 작동하지 않습니다. string 객체를 사용하려면 값을 Date 객체로 구문 분석하기 위해 애플리케이션 수준에서 추가 논리를 구현해야 합니다.

    Remote Sorting

    그리드는 Grid Remote Data Operations 항목에 설명된 원격 정렬을 지원합니다.

    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-colorsortable-header-icon-hover-color 매개 변수를 허용하는 새로운 테마를 만듭니다.

    $custom-theme: grid-theme(
        $sorted-header-icon-color: #ffb06a,
        $sortable-header-icon-hover-color: black
    );
    

    마지막 단계는 구성요소 믹스인을 포함하는 것입니다.

     @include grid($custom-theme);
    
    Note

    구성 요소가 Emulated ViewEncapsulation을 사용하는 경우::ng-deep 사용하여 이 캡슐화를 penetrate 해야 합니다.

    :host {
       ::ng-deep {
           @include grid($custom-theme);
       }
    }
    

    Defining a color palette

    방금 했던 것처럼 색상 값을 하드코딩하는 대신 igx-paletteigx-color 기능을 사용하면 색상 측면에서 더 큰 유연성을 얻을 수 있습니다.

    igx-palette 전달된 기본 색상과 보조 색상을 기반으로 색상 팔레트를 생성합니다.

    $black-color: black;
    $orange-color: #ffb06a;
    
    $custom-palette: palette($primary: $black-color, $secondary: $orange-color);
    

    그런 다음 igx-color 사용하면 팔레트에서 색상을 쉽게 검색할 수 있습니다.

    $custom-theme: grid-theme(
        $sorted-header-icon-color: color($custom-palette, "secondary", 500),
        $sortable-header-icon-hover-color: color($custom-palette, "primary", 500)
    );
    
    Note

    igx-colorigx-palette 색상을 생성하고 검색하는 강력한 기능입니다. 사용 방법에 대한 자세한 지침은 Palettes 항목을 참조하세요.

    Using Schemas

    테마 엔진을 사용하면 스키마의 이점을 활용하는 강력하고 유연한 구조를 구축할 수 있습니다. 스키마는 테마의 레시피입니다.

    모든 구성 요소에 대해 제공되는 사전 정의된 두 스키마 중 하나(이 경우_light-grid 확장합니다.

    // Extending the light grid schema
    $custom-grid-schema: extend($_light-grid,
        (
            sorted-header-icon-color: (igx-color:('secondary', 500)),
            sortable-header-icon-hover-color: (igx-color:('primary', 500))
        )
    );
    

    사용자 정의 스키마를 적용하려면 다음을 수행해야 합니다. 연장하다 전역 변수 중 하나(light 또는 dark)는 기본적으로 사용자 정의 스키마를 사용하여 구성 요소를 지적한 후 해당 구성 요소 테마에 추가합니다.

    // Extending the global light-schema
    $my-custom-schema: extend($light-schema, 
        (
            igx-grid: $custom-grid-schema
        )
    );
    
    // Defining our custom theme with the custom schema
    $custom-theme: grid-theme(
      $palette: $custom-palette,
      $schema: $my-custom-schema
    );
    

    위에서 설명한 것과 동일한 방식으로 테마를 포함하는 것을 잊지 마십시오.

    Demo

    Note

    샘플은 Change Theme에서 선택한 전역 테마의 영향을 받지 않습니다.

    API References

    Additional Resources

    우리 커뮤니티는 활동적이며 항상 새로운 아이디어를 환영합니다.