Angular 트리 그리드 구성 요소 개요

    Ignite UI for Angular 계층적 또는 평면 자체 참조 데이터를 표시하고 조작하는 데 사용됩니다. 아주 적은 코드로 데이터를 빠르게 바인딩하거나 다양한 이벤트를 사용하여 다양한 동작을 사용자 정의하세요. 이 구성 요소는 데이터 선택, Excel 스타일 필터링, 정렬, 페이징, 그룹화, 템플릿 작성, 열 이동, 열 고정, Excel 및 CSV로 내보내기 등과 같은 다양한 기능 세트를 제공합니다.

    Angular Tree Grid Example

    이 예에서는 사용자가 계층적 데이터를 표시하는 방법을 볼 수 있습니다. 필터링 및 정렬 옵션, 고정 및 숨기기, 행 선택, Excel 및 CSV로 내보내기, Sparkline 구성 요소를 사용하는 셀 템플릿이 포함되어 있습니다. 또한 Angular Pagination을 사용한 사용자 정의 페이지 매김의 예를 볼 수 있습니다.

    Getting Started with Ignite UI for Angular Tree Grid

    Ignite UI for Angular Tree Grid 구성 요소를 시작하려면 먼저 Ignite UI for Angular 설치해야 합니다. 기존 Angular 애플리케이션에서 다음 명령을 입력합니다.

    ng add igniteui-angular
    

    Ignite UI for Angular에 대한 전체 소개를 보려면 시작하기 항목을 읽어보세요.

    다음 단계는 IgxTreeGridModule 당신의 app.module.ts 파일.

    // app.module.ts
    
    import { IgxTreeGridModule } from 'igniteui-angular';
    // import { IgxTreeGridModule } from '@infragistics/igniteui-angular'; for licensed package
    
    @NgModule({
        imports: [
            ...
            IgxTreeGridModule,
            ...
        ]
    })
    export class AppModule {}
    

    또는 16.0.0부터 IgxTreeGridComponent 독립형 종속성으로 가져오거나 IGX_TREE_GRID_DIRECTIVES 토큰을 사용하여 구성 요소와 모든 지원 구성 요소 및 지시문을 가져올 수 있습니다.

    // home.component.ts
    
    import { IGX_TREE_GRID_DIRECTIVES } from 'igniteui-angular';
    // import { IGX_TREE_GRID_DIRECTIVES } from '@infragistics/igniteui-angular'; for licensed package
    
    @Component({
        selector: 'app-home',
        template: '<igx-tree-grid [data]="data"></igx-tree-grid>',
        styleUrls: ['home.component.scss'],
        standalone: true,
        imports: [IGX_TREE_GRID_DIRECTIVES]
        /* or imports: [IgxTreeGridComponent] */
    })
    export class HomeComponent {
        public data: Employee [];
    }
    

    이제 Ignite UI for Angular 가져왔으므로 igx-tree-grid 구성 요소 사용을 시작할 수 있습니다.

    Using the Angular Tree Grid

    Note

    이 구성 요소를 사용하려면 터치 상호 작용이 예상대로 작동하려면 응용 프로그램의 루트 모듈에서 HammerModule 가져와야 합니다..

    IgxTreeGridComponentIgxGridComponent와 많은 기능을 공유하지만 데이터를 계층적으로 표시하는 기능도 추가합니다. 이를 달성하기 위해 IgxTreeGridComponent는 모든 데이터 객체에 대해 하위 컬렉션을 사용하거나 모든 데이터 객체에 대해 기본 및 외래 키를 사용하여 데이터 객체 간의 관계를 정의하는 몇 가지 방법을 제공합니다.

    Tree Cells

    트리 그리드의 계층 구조(하위 컬렉션 또는 기본 및 외래 키)를 구축하는 데 사용되는 옵션에 관계없이 트리 그리드의 행은 두 가지 유형의 셀로 구성됩니다.

    • IgxGridCell- 값을 포함하는 일반 셀입니다.
    • IgxGridCell- 셀 행의 수준을 기반으로 하는 값, 확장/축소 표시기 및 들여쓰기 div 요소를 포함하는 트리 셀입니다. 행 구성 요소의 수준은 내부 treeRowlevel 속성을 통해 액세스할 수 있습니다.
    Note

    각 행에는 하나의 트리 셀만 있을 수 있지만 일반 셀은 여러 개(또는 없음) 있을 수 있습니다.

    Initial Expansion Depth

    처음에는 트리 그리드가 모든 노드 수준을 확장하여 표시합니다. 이 동작은 expansionDepth 속성을 사용하여 구성할 수 있습니다. 기본적으로 해당 값은 Infinity 이며 이는 모든 노드 수준이 확장된다는 의미입니다. 이 속성을 숫자 값으로 설정하여 초기 확장 깊이를 제어할 수 있습니다. 예를 들어 0은 루트 수준 노드만 표시하고, 1은 루트 수준 노드와 해당 하위 노드 등을 표시합니다.

    Child Collection

    하위 컬렉션 옵션을 사용하는 경우 모든 데이터 개체에는 상위 데이터 개체와 동일한 유형의 항목으로 채워지는 하위 컬렉션이 포함됩니다. 이렇게 하면 트리 그리드의 모든 레코드가 해당 하위 항목에 대한 직접적인 참조를 갖게 됩니다. 이 경우 원래 데이터 소스가 포함된 트리 그리드의 data 속성은 계층적으로 정의된 컬렉션이 됩니다.

    이 샘플에서는 다음 컬렉션 구조를 사용해 보겠습니다.

    // Sample Employee Data
    
    export const EMPLOYEE_DATA = [
        {
            Name: "Johnathan Winchester",
            ID: 1,
            HireDate: new Date(2008, 3, 20),
            Age: 55,
            Employees: [
                {
                    Name: "Michael Burke",
                    ID: 3,
                    HireDate: new Date(2011, 6, 3),
                    Age: 43,
                    Employees: []
                },
                {
                    Name: "Thomas Anderson"
                    ID: 2,
                    HireDate: new Date(2009, 6, 19),
                    Age: 29,
                    Employees: []
                },
                ...
            ]
        },
        ...
    ]
    

    이제 데이터 컬렉션을 가져와 트리 그리드의 data 입력에 바인딩하는 것부터 시작해 보겠습니다.

    <!--treeGridSample.component.html-->
    
    <igx-tree-grid #treeGrid [data]="localData">
    </igx-tree-grid>
    

    IgxTreeGridComponent가 계층 구조를 구축하려면 해당 childDataKey 속성을 각 데이터 객체에 사용되는 하위 컬렉션의 이름으로 설정해야 합니다. 우리의 경우에는 Employees 컬렉션이 됩니다. 또한 자동 열 생성을 비활성화하고 이를 데이터 개체의 실제 속성과 일치시켜 수동으로 정의합니다. (직원 컬렉션은 계층 구조에 자동으로 사용되므로 열 정의에 이를 포함할 필요가 없습니다.)

    <!--treeGridSample.component.html-->
    
    <igx-tree-grid #treeGrid [data]="localData" childDataKey="Employees"
                   [autoGenerate]="false">
        <igx-column field="Name" dataType="string"></igx-column>
        <igx-column field="HireDate" dataType="date"></igx-column>
        <igx-column field="Age" dataType="number"></igx-column>
    </igx-tree-grid>
    

    이제 rowSelectionpaging 기능을 활성화하겠습니다. 또한 첫 번째 열의 요약 기능과 각 열의 필터링, 정렬, 편집, 이동 및 크기 조정 기능을 활성화합니다.

    <!--treeGridSample.component.html-->
    
    <igx-tree-grid #treeGrid [data]="localData" childDataKey="Employees"
                   [autoGenerate]="false" [rowSelection]="'multiple'" [allowFiltering]="true" [moving]="true">
        <igx-column field="Name" dataType="string" [sortable]="true" [editable]="true" [resizable]="true"
                    [hasSummary]="true"></igx-column>
        <igx-column field="HireDate" dataType="date" [sortable]="true" [editable]="true" [resizable]="true"></igx-column>
        <igx-column field="Age" dataType="number" [sortable]="true" [editable]="true" [resizable]="true"></igx-column>
        <igx-paginator>
        </igx-paginator>
    </igx-tree-grid>
    

    마지막으로 IgxGridToolbarComponent, IgxGridToolbarHidingComponent, IgxGridToolbarPinningComponentIgxGridToolbarExporterComponent를 각각 사용하여 열 숨기기, 열 고정 및 내보내기 기능과 함께 트리 그리드의 도구 모음을 활성화하겠습니다.

    <!--treeGridSample.component.html-->
    
    <igx-tree-grid #treeGrid [data]="localData" childDataKey="Employees"
                   [autoGenerate]="false" [rowSelection]="'multiple'" [allowFiltering]="true" [moving]="true">
        <igx-grid-toolbar>
                <igx-grid-toolbar-title>Employees</igx-grid-toolbar-title>
                <igx-grid-toolbar-actions>
                    <igx-grid-toolbar-hiding></igx-grid-toolbar-hiding>
                    <igx-grid-toolbar-pinning></igx-grid-toolbar-pinning>
                    <igx-grid-toolbar-exporter></igx-grid-toolbar-exporter>
                </igx-grid-toolbar-actions>
        </igx-grid-toolbar>
        <igx-column field="Name" dataType="string" [sortable]="true" [editable]="true" [resizable]="true"></igx-column>
        <igx-column field="HireDate" dataType="date" [sortable]="true" [editable]="true" [resizable]="true"></igx-column>
        <igx-column field="Age" dataType="number" [sortable]="true" [editable]="true" [resizable]="true"></igx-column>
        <igx-paginator [perPage]="6">
        </igx-paginator>
    </igx-tree-grid>
    

    Angular Tree Grid 예제 섹션의 이 문서 시작 부분에서 위의 코드 결과를 볼 수 있습니다.

    Primary and Foreign keys

    기본 및 외래 키 옵션을 사용하는 경우 모든 데이터 개체에는 기본 키와 외래 키가 포함됩니다. 기본 키는 현재 데이터 개체의 고유 식별자이고 외래 키는 상위 개체의 고유 식별자입니다. 이 경우 원래 데이터 소스가 포함된 트리 그리드의 data 속성은 플랫 컬렉션이 됩니다.

    다음은 기본 키와 외래 키 관계로 정의된 단순 컬렉션을 포함하는 구성 요소의 예입니다.

    // treeGridSample.component.ts
    
    @Component({...})
    export class MyComponent implements OnInit {
    
        public data: any[];
    
        constructor() { }
    
        public ngOnInit() {
            // Primary and Foreign keys sample data
            this.data = [
                { ID: 1, ParentID: -1, Name: "Casey Houston", JobTitle: "Vice President", Age: 32 },
                { ID: 2, ParentID: 1, Name: "Gilberto Todd", JobTitle: "Director", Age: 41 },
                { ID: 3, ParentID: 2, Name: "Tanya Bennett", JobTitle: "Director", Age: 29 },
                { ID: 4, ParentID: 2, Name: "Jack Simon", JobTitle: "Software Developer", Age: 33 },
                { ID: 5, ParentID: 8, Name: "Celia Martinez", JobTitle: "Senior Software Developer", Age: 44 },
                { ID: 6, ParentID: -1, Name: "Erma Walsh", JobTitle: "CEO", Age: 52 },
                { ID: 7, ParentID: 2, Name: "Debra Morton", JobTitle: "Associate Software Developer", Age: 35 },
                { ID: 8, ParentID: 10, Name: "Erika Wells", JobTitle: "Software Development Team Lead", Age: 50 },
                { ID: 9, ParentID: 8, Name: "Leslie Hansen", JobTitle: "Associate Software Developer", Age: 28 },
                { ID: 10, ParentID: -1, Name: "Eduardo Ramirez", JobTitle: "Development Manager", Age: 53 }
            ];
        }
    }
    

    위의 샘플 데이터에서 모든 레코드에는 ID, ParentID 및 이름, JobTitle 및 Age와 같은 일부 추가 속성이 있습니다. 앞서 언급했듯이 레코드 ID는 고유해야 합니다. ParentID에는 상위 노드의 ID가 포함됩니다. 행에 트리 그리드의 어떤 행과도 일치하지 않는 ParentID가 있는 경우 이는 이 행이 루트 행임을 의미합니다.

    부모-자식 관계는 트리 그리드의 primaryKeyforeignKey 속성을 사용하여 구성됩니다.

    다음은 위의 플랫 컬렉션에 정의된 데이터를 표시하도록 트리 그리드를 구성하는 방법을 보여주는 구성 요소의 템플릿입니다.

    <!--treeGridSample.component.html-->
    
    <igx-tree-grid #treeGrid [data]="data" primaryKey="ID" foreignKey="ParentID"
        [autoGenerate]="false">
        <igx-column field="Name" dataType="string"></igx-column>
        <igx-column field="JobTitle" dataType="string"></igx-column>
        <igx-column field="Age" dataType="number"></igx-column>
    </igx-tree-grid>
    

    또한 rowSelection 속성을 사용하고 각 열에 대한 필터링, 정렬, 편집, 이동 및 크기 조정 기능을 사용하여 트리 그리드의 행 선택 기능을 활성화합니다.

    <!--treeGridSample.component.html-->
    
    <igx-tree-grid #treeGrid [data]="data" primaryKey="ID" foreignKey="ParentID"
        [autoGenerate]="false" [rowSelection]="'multiple'" [allowFiltering]="true" [moving]="true">
        <igx-column field="Name" dataType="string" [sortable]="true" [editable]="true" [resizable]="true"></igx-column>
        <igx-column field="JobTitle" dataType="string" [sortable]="true" [editable]="true" [resizable]="true"></igx-column>
        <igx-column field="Age" dataType="number" [sortable]="true" [editable]="true" [resizable]="true"></igx-column>
    </igx-tree-grid>
    

    최종 결과는 다음과 같습니다.

    Persistence and Integration

    트리 셀의 들여쓰기는 필터링, 정렬, 페이징과 같은 다른 트리 그리드 기능 전반에 걸쳐 유지됩니다.

    • 열에 정렬이 적용되면 데이터 행이 수준별로 정렬됩니다. 즉, 루트 수준 행은 해당 하위 항목과 독립적으로 정렬됩니다. 각각의 하위 컬렉션도 각각 독립적으로 정렬됩니다.
    • 첫 번째 열(visibleIndex가 0인 열)은 항상 트리 열입니다.
    • 열 고정, 열 숨기기, 열 이동 등의 작업 후 visibleIndex가 0으로 끝나는 열이 트리 열이 됩니다.
    • 내보낸 Excel 워크시트는 트리 그리드 자체에 그룹화된 레코드를 그룹화하여 계층 구조를 반영합니다. 모든 레코드 확장 상태도 유지되고 반영됩니다.
    • CSV로 내보낼 때 레벨 및 확장 상태가 무시되고 모든 데이터가 플랫으로 내보내집니다.

    Angular Tree Grid Sizing

    그리드 크기 조정 항목을 참조하세요.

    Angular Tree Grid Styling

    트리 그리드를 사용하면 Ignite UI for Angular 통해 스타일을 지정할 수 있습니다. 트리 그리드의 테마는 트리 그리드의 모든 기능을 사용자 정의할 수 있는 다양한 속성을 노출합니다.

    트리 그리드 스타일링을 시작하려면 모든 테마 기능과 구성 요소 믹스인이 있는 index 파일을 가져와야 합니다.

    @import '~igniteui-angular/lib/core/styles/themes/index';
    

    가장 간단한 접근 방식에 따라 grid-theme 확장하고 원하는 대로 트리 그리드를 사용자 정의하는 데 필요한 매개변수를 허용하는 새로운 테마를 만듭니다.

    Note

    특정 sass 트리 그리드 기능은 없습니다.

    $custom-theme: grid-theme(
      $cell-active-border-color: #FFCD0F,
      $cell-selected-background: #6F6F6F,
      $row-hover-background: #F8E495,
      $row-selected-background: #8D8D8D,
      $header-background: #494949,
      $header-text-color: #FFF,
      $expand-icon-color: #FFCD0F,
      $expand-icon-hover-color: #E0B710,
      $resize-line-color: #FFCD0F,
      $row-highlight: #FFCD0F
    );
    

    마지막 단계는 애플리케이션에 구성 요소 테마를 포함하는 것입니다.

    @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 전달된 기본 색상과 보조 색상을 기반으로 색상 팔레트를 생성합니다.

    $yellow-color: #FFCD0F;
    $black-color: #494949;
    $custom-palette: palette($primary: $black-color, $secondary: $yellow-color);
    

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

    $custom-theme: grid-theme(
        $cell-active-border-color: color($custom-palette, "secondary", 500),
        $cell-selected-background: color($custom-palette, "primary", 300),
        $row-hover-background: color($custom-palette, "secondary", 100),
        $row-selected-background: color($custom-palette, "primary", 100),
        $header-background: color($custom-palette, "primary", 500),
        $header-text-color:contrast-color($custom-palette, "primary", 500),
        $expand-icon-color: color($custom-palette, "secondary", 500),
        $expand-icon-hover-color: color($custom-palette, "secondary", 600),
        $resize-line-color: color($custom-palette, "secondary", 500),
        $row-highlight: color($custom-palette, "secondary", 500)
    );
    

    Using Schemas

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

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

    // Extending the light tree grid schema
    $custom-grid-schema: extend($_light-grid, (
        cell-active-border-color: (igx-color:('secondary', 500)),
        cell-selected-background: (igx-color:('primary', 300)),
        row-hover-background: (igx-color:('secondary', 100)),
        row-selected-background: (igx-color:('primary', 100)),
        header-background: (igx-color:('primary', 500)),
        header-text-color: (igx-contrast-color:('primary', 500)),
        expand-icon-color: (igx-color:('secondary', 500)),
        expand-icon-hover-color: (igx-color:('secondary', 600)),
        resize-line-color: (igx-color:('secondary', 500)),
        row-highlight: (igx-color:('secondary', 500))
    ));
    

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

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

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

    Angular Tree Grid Styling Demo

    Note

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

    Performance (Experimental)

    igxTreeGrid의 설계를 통해 Angular에 도입된 이벤트 통합 기능을 활용할 수 있습니다. 이 기능을 사용하면 상호 작용 및 응답성 측면에서 약 20% 정도 향상된 성능을 얻을 수 있습니다. 이 기능은 bootstrapModule 메소드에서 ngZoneEventCoalescingngZoneRunCoalescing 속성을 true로 설정하여 애플리케이션 수준에서 활성화할 수 있습니다.

    platformBrowserDynamic()
      .bootstrapModule(AppModule, { ngZoneEventCoalescing: true, ngZoneRunCoalescing: true })
      .catch(err => console.error(err));
    
    Note

    이는 아직 igxTreeGrid에 대한 실험적 기능입니다. 이는 트리 그리드에 예상치 못한 동작이 있을 수 있음을 의미합니다. 그러한 행동이 발생하는 경우 Github 페이지로 문의해 주세요.

    Note

    이를 활성화하면 igxTreeGrid와 관련되지 않은 Angular 애플리케이션의 다른 부분에 영향을 미칠 수 있습니다.

    Known Limitations

    한정 설명
    트리 셀 템플릿 트리 셀을 템플릿으로 만들 때 셀 경계 외부에 있는 콘텐츠는 오버레이에 배치되지 않는 한 표시되지 않습니다.
    그룹화 기준 그룹화 기준 기능은 트리 그리드에 내재되어 있으므로 지원되지 않습니다.
    Note

    트리 그리드의 깊이 제한은 25개 수준입니다. 더 많은 레벨을 지원하려면 애플리케이션에 사용자 정의 CSS 클래스를 추가해야 합니다. 아래에서 이러한 CSS 클래스의 예를 볼 수 있습니다.

    .igx-grid__tree-cell--padding-level-26 {
        padding-left: 39rem;
    }
    
    Note

    igxTreeGrid 내부적으로 igxForOf 지시문을 사용하므로 모든 igxForOf 제한 사항은 igxTreeGrid에 유효합니다. 자세한 내용은 igxForOf 알려진 문제 섹션을 참조하세요.

    API References

    Theming Dependencies

    Additional Resources

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