Angular 계층적 데이터 그리드 구성 요소 개요

    Ignite UI for Angular Hierarchical Data Grid는 계층적 테이블 형식 데이터를 표시하고 조작하는 데 사용됩니다. 아주 적은 코드로 데이터를 빠르게 바인딩하거나 다양한 이벤트를 사용하여 다양한 동작을 사용자 지정할 수 있습니다. 이 구성 요소는 데이터 선택, Excel 스타일 필터링, 정렬, 페이징, 템플릿, 열 이동, 열 고정, Excel 및 CSV로 내보내기 등과 같은 다양한 기능을 제공합니다. Hierarchical Grid는 Flat Grid Component를 기반으로 하며, 사용자가 부모 그리드의 행을 확장하거나 축소할 수 있도록 하여 기능을 확장하고, 더 자세한 정보가 필요할 때 해당 자식 그리드를 표시합니다.

    Angular Hierarchical Data Grid Example

    이 각도 그리드 예에서는 사용자가 계층적 데이터 세트를 시각화하고 셀 템플릿을 사용하여 Sparkline과 같은 다른 시각적 구성 요소를 추가하는 방법을 볼 수 있습니다.

    Getting Started with Ignite UI for Angular Hierarchical Data Grid

    메모

    This component can utilize the HammerModule optionally. It can be imported in the root module of the application in order for touch interactions to work as expected..

    Ignite UI for Angular Hierarchical Data Grid 구성 요소를 시작하려면 먼저 Ignite UI for Angular를 설치해야 합니다. 기존 Angular 응용 프로그램에서 다음 명령을 입력합니다.

    ng add igniteui-angular
    

    Ignite UI for Angular에 대한 전체 소개는 시작 항목을 참조하십시오.

    The next step is to import the IgxHierarchicalGridModule in your app.module.ts file.

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

    Alternatively, as of 16.0.0 you can import the IgxHierarchicalGridComponent as a standalone dependency, or use the IGX_HIERARCHICAL_GRID_DIRECTIVES token to import the component and all of its supporting components and directives.

    // home.component.ts
    
    import { IGX_HIERARCHICAL_GRID_DIRECTIVES } from 'igniteui-angular';
    // import { IGX_HIERARCHICAL_GRID_DIRECTIVES } from '@infragistics/igniteui-angular'; for licensed package
    
    @Component({
        selector: 'app-home',
        template: `
        <igx-hierarchical-grid #hierarchicalGrid [data]="singers" [autoGenerate]="true">
            <igx-row-island [key]="'Albums'" [autoGenerate]="true">
                <igx-row-island [key]="'Songs'" [autoGenerate]="true">
                </igx-row-island>
            </igx-row-island>
            <igx-row-island [key]="'Tours'" [autoGenerate]="true">
            </igx-row-island>
        </igx-hierarchical-grid>
        `,
        styleUrls: ['home.component.scss'],
        standalone: true,
        imports: [IGX_HIERARCHICAL_GRID_DIRECTIVES]
        /* or imports: [IgxHierarchicalGridComponent, IgxRowIslandComponent] */
    })
    export class HomeComponent {
        public singers: Artist [];
    }
    

    Now that you have the Ignite UI for Angular Hierarchical Grid module or directives imported, you can start using the igx-hierarchical-grid component.

    Using the Angular Hierarchical Data Grid

    데이터 바인딩

    igx-hierarchical-grid derives from igx-grid and shares most of its functionality. The main difference is that it allows multiple levels of hierarchy to be defined. They are configured through a separate tag within the definition of igx-hierarchical-grid, called igx-row-island. The igx-row-island component defines the configuration for each child grid for the particular level. Multiple row islands per level are also supported. The Hierarchical Grid supports two ways of binding to data:

    계층적 데이터 사용

    애플리케이션이 전체 계층 데이터를 개체의 하위 배열을 참조하는 개체 배열로 로드하는 경우 계층 그리드는 이를 읽고 자동으로 바인딩하도록 구성할 수 있습니다. 다음은 적절하게 구조화된 계층적 데이터 원본의 예입니다.

    export const singers = [{
        "Artist": "Naomí Yepes",
        "Photo": "assets/images/hgrid/naomi.png",
        "Debut": "2011",
        "Grammy Nominations": 6,
        "Grammy Awards": 0,
        "Tours": [{
            "Tour": "Faithful Tour",
            "Started on": "Sep-12",
            "Location": "Worldwide",
            "Headliner": "NO",
            "Toured by": "Naomí Yepes"
        }],
        "Albums": [{
            "Album": "Dream Driven",
            "Launch Date": new Date("August 25, 2014"),
            "Billboard Review": "81",
            "US Billboard 200": "1",
            "Artist": "Naomí Yepes",
            "Songs": [{
                "No.": "1",
                "Title": "Intro",
                "Released": "*",
                "Genre": "*",
                "Album": "Dream Driven"
            }]
        }]
    }];
    

    Each igx-row-island should specify the key of the property that holds the children data.

    <igx-hierarchical-grid #hierarchicalGrid [data]="singers" [autoGenerate]="true">
        <igx-row-island [key]="'Albums'" [autoGenerate]="true">
            <igx-row-island [key]="'Songs'" [autoGenerate]="true">
            </igx-row-island>
        </igx-row-island>
        <igx-row-island [key]="'Tours'" [autoGenerate]="true">
        </igx-row-island>
    </igx-hierarchical-grid>
    
    메모

    Note that instead of data the user configures only the key that the igx-hierarchical-grid needs to read to set the data automatically.

    Load-On-Demand 사용

    Most applications are designed to load as little data as possible initially, which results in faster load times. In such cases igx-hierarchical-grid may be configured to allow user-created services to feed it with data on demand. The following configuration uses a special @Output and a newly introduced loading-in-progress template to provide a fully-featured load-on-demand.

    <!-- hierarchicalGridSample.component.html -->
    
    <igx-hierarchical-grid #hGrid [primaryKey]="'CustomerID'" [autoGenerate]="true" [height]="'600px'" [width]="'100%'">
        <igx-row-island [key]="'Orders'" [primaryKey]="'OrderID'" [autoGenerate]="true"  (gridCreated)="gridCreated($event, 'CustomerID')">
            <igx-row-island [key]="'Order_Details'" [primaryKey]="'ProductID'" [autoGenerate]="true" (gridCreated)="gridCreated($event, 'OrderID')">
            </igx-row-island>
        </igx-row-island>
    </igx-hierarchical-grid>
    
    //  hierarchicalGridSample.component.ts
    
    @Component({...})
    export class HierarchicalGridLoDSampleComponent implements AfterViewInit {
        @ViewChild("hGrid")
        public hGrid: IgxHierarchicalGridComponent;
    
        constructor(private remoteService: RemoteLoDService) { }
    
        public ngAfterViewInit() {
            this.hGrid.isLoading = true;
            this.remoteService.getData({ parentID: null, rootLevel: true, key: "Customers" }).subscribe((data) => {
                this.hGrid.isLoading = false;
                this.hGrid.data = data;
                this.hGrid.cdr.detectChanges();
            });
        }
    
        public gridCreated(event: IGridCreatedEventArgs, _parentKey: string) {
            const dataState = {
                key: event.owner.key,
                parentID: event.parentID,
                parentKey: _parentKey,
                rootLevel: false
            };
            event.grid.isLoading = true;
            this.remoteService.getData(dataState).subscribe(
                (data) => {
                    event.grid.isLoading = false;
                    event.grid.data = data;
                    event.grid.cdr.detectChanges();
                }
            );
        }
    }
    
    // remote-load-on-demand.service.ts
    
    @Injectable()
    export class RemoteLoDService {
        public url = `https://services.odata.org/V4/Northwind/Northwind.svc/`;
    
        constructor(private http: HttpClient) { }
    
        public getData(dataState?: any): Observable<any[]> {
            return this.http.get(this.buildUrl(dataState)).pipe(
                map((response) => response["value"])
            );
        }
    
        public buildUrl(dataState) {
            let qS = "";
            if (dataState) {
                qS += `${dataState.key}?`;
    
                if (!dataState.rootLevel) {
                    if (typeof dataState.parentID === "string") {
                        qS += `$filter=${dataState.parentKey} eq '${dataState.parentID}'`;
                    } else {
                        qS += `$filter=${dataState.parentKey} eq ${dataState.parentID}`;
                    }
                }
            }
            return `${this.url}${qS}`;
        }
    }
    

    행 확장 표시기 숨기기/표시

    If you have a way to provide information whether a row has children prior to its expanding, you could use the hasChildrenKey input property. This way you could provide a boolean property from the data objects which indicates whether an expansion indicator should be displayed.

    <igx-hierarchical-grid #grid [data]="data" primaryKey="ID" hasChildrenKey="hasChildren">
            ...
    </igx-hierarchical-grid>
    

    Note that setting the hasChildrenKey property is not required. In case you don't provide it, expansion indicators will be displayed for each row.

    또한 헤더 확장/모두 축소 표시기를 표시하거나 숨기려면 showExpandAll 속성을 사용할 수 있습니다. 이 UI는 성능상의 이유로 기본적으로 비활성화되어 있으며 대용량 데이터가 있는 그리드나 온디맨드 로드가 있는 그리드에서는 활성화하지 않는 것이 좋습니다.

    특징

    The grid features could be enabled and configured through the igx-row-island markup - they get applied for every grid that is created for it. Changing options at runtime through the row island instance changes them for each of the grids it has spawned.

    <igx-hierarchical-grid [data]="localData" [autoGenerate]="false"
        [allowFiltering]='true' [height]="'600px'" [width]="'800px'" #hGrid>
        <igx-column field="ID" [pinned]="true" [filterable]='true'></igx-column>
        <igx-column-group header="Information">
            <igx-column field="ChildLevels"></igx-column>
            <igx-column field="ProductName" hasSummary='true'></igx-column>
        </igx-column-group>
        <igx-row-island [key]="'childData'" [autoGenerate]="false" [rowSelection]="'multiple'" #layout1>
            <igx-column field="ID" [hasSummary]='true' [dataType]="'number'"></igx-column>
            <igx-column-group header="Information2">
                <igx-column field="ChildLevels"></igx-column>
                <igx-column field="ProductName"></igx-column>
            </igx-column-group>
            <igx-paginator *igxPaginator [perPage]="5"></igx-paginator>
        </igx-row-island>
        <igx-paginator>
        </igx-paginator>
    </igx-hierarchical-grid>
    

    다음 그리드 기능은 그리드 수준별로 작동합니다. 즉, 각 그리드 인스턴스가 나머지 그리드와 독립적으로 해당 기능을 관리합니다.

    • 정렬
    • 필터링
    • 페이징
    • 다중 열 헤더
    • 숨김
    • 고정
    • 움직이는
    • 요약
    • 찾다

    The Selection and Navigation features work globally for the whole igx-hierarchical-grid

    • 선택 선택에서는 두 개의 서로 다른 하위 그리드에 대해 선택한 셀이 동시에 표시되는 것을 허용하지 않습니다.
    • 탐색 위/아래로 탐색할 때 다음/이전 요소가 하위 그리드인 경우 관련 하위 그리드에서 탐색이 계속되며 관련 셀이 선택되고 초점이 맞춰진 것으로 표시됩니다. 하위 셀이 현재 표시되는 뷰 포트 외부에 있는 경우 선택한 셀이 항상 표시되도록 뷰로 스크롤됩니다.

    모두 축소 버튼

    계층적 그리드를 사용하면 사용자는 왼쪽 상단 모서리에 있는 "모두 축소" 버튼을 눌러 현재 확장된 모든 행을 편리하게 축소할 수 있습니다. 또한 다른 그리드를 포함하고 계층적 그리드 자체인 모든 하위 그리드에도 다음과 같은 버튼이 있습니다. 이 방법으로 사용자는 계층 구조에서 지정된 그리드만 축소할 수 있습니다.

    콜랩스 올 아이콘

    사이징

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

    CRUD 작업

    메모

    An important difference from the flat Data Grid is that each instance for a given row island has the same transaction service instance and accumulates the same transaction log. In order to enable the CRUD functionality users should inject the IgxHierarchicalTransactionServiceFactory.

    CRUD API 메서드 호출은 여전히 각 개별 그리드 인스턴스를 통해 수행되어야 합니다.

    igxGrid를 사용하여 CRUD 작업을 빌드하는 방법 주제를 확인하세요.

    스타일링

    The igxHierarchicalGrid allows styling through the Ignite UI for Angular Theme Library. The grid's grid-theme exposes a wide variety of properties, which allow the customization of all the features of the grid.

    아래 단계에서는 igxHierarchicalGrid 스타일을 사용자 정의하는 단계를 진행합니다.

    글로벌 테마 가져오기

    To begin the customization of the hierarchical grid, you need to import the index file, where all styling functions and mixins are located.

    @use "igniteui-angular/theming" as *;
    
    // IMPORTANT: Prior to Ignite UI for Angular version 13 use:
    // @import '~igniteui-angular/lib/core/styles/themes/index';
    

    맞춤 테마 정의

    Next, create a new theme, that extends the grid-theme and accepts the parameters, required to customize the hierarchical grid as desired.

    메모

    There is no specific sass hierarchical grid function.

    $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
    );
    
    메모

    Instead of hardcoding the color values like we just did, we can achieve greater flexibility in terms of colors by using the palette and color functions. Please refer to Palettes topic for detailed guidance on how to use them.

    사용자 정의 테마 적용

    The easiest way to apply your theme is with a sass @include statement in the global styles file:

    @include css-vars($custom-theme);
    

    In order for the custom theme do affect only specific component, you can move all of the styles you just defined from the global styles file to the custom component's style file (including the import of the index file). This way, due to Angular's ViewEncapsulation, your styles will be applied only to your custom component.

    데모

    메모

    The sample will not be affected by the selected global theme from Change Theme.

    퍼포먼스 (실험)

    The igxHierarchicalGrid's design allows it to take advantage of the Event Coalescing feature that has Angular introduced. This feature allows for improved performance with roughly around 20% in terms of interactions and responsiveness. This feature can be enabled on application level by simply setting the ngZoneEventCoalescing and ngZoneRunCoalescing properties to true in the bootstrapModule method:

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

    This is still in experimental feature for the igxHierarchicalGrid. This means that there might be some unexpected behaviors in the Hierarchical Grid. In case of encountering any such behavior, please contact us on our Github page.

    메모

    Enabling it can affects other parts of an Angular application that the igxHierarchicalGrid is not related to.

    알려진 제한 사항

    한정 설명
    그룹화 기준 그룹화 기준 기능은 계층형 그리드에서 지원되지 않습니다.
    메모

    igxHierarchicalGrid uses igxForOf directive internally hence all igxForOf limitations are valid for igxHierarchicalGrid. For more details see igxForOf Known Issues section.

    API 참조

    테마 종속성

    추가 리소스

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