Angular Tree Grid Remote Data Operations

    Ignite UI for Angular 원격 가상화, 원격 정렬, 원격 필터링 등과 같은 원격 데이터 작업을 지원합니다. 이를 통해 개발자는 서버에서 이러한 작업을 수행하고 생성된 데이터를 검색하여 Tree Grid에 표시할 수 있습니다.

    Angular Tree Grid Remote Data Operations Overview Example

    기본적으로 트리 그리드는 데이터 작업을 수행하기 위해 자체 논리를 사용합니다. 이러한 작업을 원격으로 수행하고 트리 그리드에 의해 노출되는 특정 입력 및 이벤트를 활용하여 결과 데이터를 트리 그리드에 공급할 수 있습니다.

    Remote Filtering

    To provide remote filtering, you need to subscribe to the filteringExpressionsTreeChange output so that you make the appropriate request based on the arguments received. Let's use a flat collection as a data source for our Tree Grid by providing a primaryKey and a foreignKey.

    We will also take advantage of the rxjs debounceTime function, which emits a value from the source Observable only after a particular time span has passed without another source emission. This way the remote operation will be triggered only when the specified amount of time has passed without the user interrupting it.

    const DEBOUNCE_TIME = 300;
    ...
    public ngAfterViewInit() {
        ...
        this.treeGrid.filteringExpressionsTreeChange.pipe(
            debounceTime(DEBOUNCE_TIME),
            takeUntil(this.destroy$)
        ).subscribe(() => {
            this.processData();
        });
    }
    

    When remote filtering is provided, usually we do not need the built-in filtering of the Tree Grid. We can disable it by setting the filterStrategy input of the Tree Grid to the NoopFilteringStrategy instance.

    <!-- tree-grid-remote-filtering-sample.html -->
    
    <igx-tree-grid #treeGrid [data]="remoteData | async" primaryKey="ID" foreignKey="ParentID"
                   [autoGenerate]="false"
                   [filterStrategy]="noopFilterStrategy"
                   [allowFiltering]="true">
        <igx-column [field]="'Name'" dataType="string"></igx-column>
        <igx-column [field]="'Title'" dataType="string"></igx-column>
        <igx-column [field]="'Age'" dataType="number"></igx-column>
    </igx-tree-grid>
    
    // tree-grid-remote-filtering-sample.ts
    
    public noopFilterStrategy = NoopFilteringStrategy.instance();
    
    public processData() {
        this.treeGrid.isLoading = true;
    
        const filteringExpr = this.treeGrid.filteringExpressionsTree;
    
        this._remoteService.getData(filteringExpr, () => {
            this.treeGrid.isLoading = false;
        });
    }
    

    원격 필터링은 플랫 컬렉션에 대해 직접 수행되어야 합니다. 또한 상위 항목이 필터링과 일치하는지 여부에 관계없이 필터링 조건과 일치하는 모든 레코드에 대해 모든 상위 항목을 포함해야 합니다(계층 구조를 그대로 유지하기 위해 이 작업을 수행함). 결과는 아래에서 볼 수 있습니다:

    Note

    원격 데이터가 요청되면 필터링 작업은 대소문자를 구분합니다.

    Remote Filtering Demo

    데모 섹션의 이 문서 시작 부분에서 위의 코드 결과를 볼 수 있습니다.

    Unique Column Values Strategy

    The list items inside the Excel Style Filtering dialog represent the unique values for the respective column. The Tree Grid generates these values based on its data source by default. In case of remote filtering, the grid data does not contain all the data from the server. In order to provide the unique values manually and load them on demand, we can take advantage of the Tree Grid's uniqueColumnValuesStrategy input. This input is actually a method that provides three arguments:

    • - 해당 열 인스턴스입니다.
    • filteringExpressionsTree- 해당 열을 기준으로 축소된 필터링 표현식 트리입니다.
    • done- 서버에서 검색될 때 새로 생성된 열 값으로 호출되어야 하는 콜백입니다.

    개발자는 열과​ ​filteringExpressionsTree 인수에서 제공되는 정보를 기반으로 필요한 고유 열 값을 수동으로 생성한 다음 완료 콜백을 호출할 수 있습니다.

    Note

    입력이uniqueColumnValuesStrategy 제공되면, 엑셀 스타일 필터링의 기본 고유 값 생성 프로세스는 사용되지 않습니다.

    <igx-tree-grid #treeGrid [data]="data" [filterMode]="'excelStyleFilter'" [uniqueColumnValuesStrategy]="columnValuesStrategy">
        ...
    </igx-tree-grid>
    
    public columnValuesStrategy = (column: ColumnType,
                                   columnExprTree: IFilteringExpressionsTree,
                                   done: (uniqueValues: any[]) => void) => {
        // Get specific column data.
        this.remoteValuesService.getColumnData(column, columnExprTree, uniqueValues => done(uniqueValues));
    }
    

    Unique Column Values Strategy Demo

    엑셀 스타일 필터링을 위한 맞춤 로딩 템플릿을 제공하기 위해 다음igxExcelStyleLoading 지시를 사용할 수 있습니다:

    <igx-tree-grid [data]="data" [filterMode]="'excelStyleFilter'" [uniqueColumnValuesStrategy]="columnValuesStrategy">
        ...
        <ng-template igxExcelStyleLoading>
            Loading ...
        </ng-template>
    </igx-tree-grid>
    

    Remote Paging

    In this sample we will demonstrate how to display a certain number of root records per page no matter how many child records they have. In order to cancel the built-in Tree Grid paging algorithm, which displays a certain number of records no matter their level (root or child), we have to set the perPage property to Number.MAX_SAFE_INTEGER.

    <igx-tree-grid #treeGrid ...>
            <igx-paginator [perPage]="maxPerPage">
            </igx-paginator>
    ...
    
    public maxPerPage = Number.MAX_SAFE_INTEGER;
    

    이제 저희가 직접 맞춤 페이징 템플릿을 설정할지, 아니면 기본igx-paginator 템플릿을 사용할 수 있겠죠. 먼저 기본 페이징 템플릿을 사용해 원격 페이징을 설정하는 데 필요한 사항을 살펴보겠습니다.

    Remote paging with default template

    기본 페이징 템플릿을 사용하려면 Paginator의totalRecords 속성을 설정해야 하며, 그래야 그리드가 전체 원격 레코드를 기반으로 전체 페이지 수를 계산할 수 있습니다. 원격 페이지네이션을 수행할 때 페이지네이터는 현재 페이지의 데이터만 그리드에 전달하므로, 그리드는 제공된 데이터 소스를 페이지네이션하려 하지 않습니다. 그래서 Grid의pagingMode 속성을 GridPagingMode.remote로 설정해야 합니다. 또한 원격 서비스에서 데이터를 가져오려면 이벤트에 구독pagingDoneperPageChange 해야 하며, 어떤 이벤트를 사용할지는 사용 사례에 따라 다릅니다.

    <igx-tree-grid #treeGrid [data]="data | async" childDataKey="Content" [pagingMode]="mode">
        <igx-column field="Name"></igx-column>
        ...
        <igx-paginator [(page)]="page" [(perPage)]="perPage" [totalRecords]="totalCount"
            (pagingDone)="paginate($event.current)">
        </igx-paginator>
    </igx-tree-grid>
    
    public totalCount = 0;
    public data: Observable<any[]>;
    public mode = GridPagingMode.remote;
    public isLoading = true;
    @ViewChild('grid1', { static: true }) public grid1: IgxGridComponent;
    
    private _dataLengthSubscriber;
    
    public set perPage(val: number) {
        this._perPage = val;
        this.paginate(0);
    }
    
    public ngOnInit() {
        this.data = this.remoteService.remoteData.asObservable();
    
        this._dataLengthSubscriber = this.remoteService.getDataLength().subscribe((data: any) => {
            this.totalCount = data;
            this.grid1.isLoading = false;
        });
    }
    
    public ngAfterViewInit() {
        const skip = this.page * this.perPage;
        this.remoteService.getData(skip, this.perPage);
    }
    
    public paginate(page: number) {
        this.page = page;
        const skip = this.page * this.perPage;
        const top = this.perPage;
    
        this.remoteService.getData(skip, top);
    }
    

    Remote Paging with custom igx-paginator-content

    커스텀 페이지네이터 콘텐츠를 정의할 때, 요청된 페이지에만 데이터를 얻고 올바른 데이터를 전달할 수 있도록 콘텐츠를 정의해야 합니다 거르다 그리고 맨 위로 선택한 페이지와 항목에 따라 원격 서비스에 대한 매개변수perPage. 우리는<igx-paginator> 예제 구성을 쉽게 하기 위해,IgxPageSizeSelectorComponent 그리고IgxPageNavigationComponent 도입된 사람들 -igx-page-size페이지별 드롭다운과 라벨을 추가합니다igx-page-nav 내비게이션 액션 버튼과 라벨을 추가할 예정입니다.

    <igx-paginator #paginator
        [totalRecords]="totalCount"
        [(perPage)]="perPage"
        [selectOptions]="selectOptions"
        (pageChange)="paginate($event)">
        <igx-paginator-content>
            <igx-page-size></igx-page-size>
            [This is my custom content]
            <igx-page-nav></igx-page-nav>
        </igx-paginator-content>
    </igx-paginator>
    
    public paginate(page: number) {
        this.page = page;
        const skip = this.page * this.perPage;
        const top = this.perPage;
    
        this.remoteService.getData(skip, top);
    }
    
    Note

    원격 페이징을 올바르게 구성하려면 다음을GridPagingMode.Remote 설정해야 합니다:

    <igx-tree-grid #treeGrid [data]="data | async" childDataKey="Content"
            expansionDepth="0" width="100%" height="540px" [pagingMode]="mode"></igx-tree-grid>
    ...
    public mode = GridPagingMode.Remote;
    

    마지막 단계는 요구 사항에 따라 페이지네이터 콘텐츠를 선언하는 것입니다.

    <igx-paginator-content>
        <igx-page-size></igx-page-size>
        [This is my custom content]
        <igx-page-nav></igx-page-nav>
    </igx-paginator-content>
    

    위의 모든 변경 후에는 다음과 같은 결과가 달성됩니다.

    Known Issues and Limitations

    • 그리드에 세트가 없primaryKey 고 원격 데이터 시나리오가 활성화되어 있을 때(페이징, 정렬, 필터링, 스크롤 시 원격 서버에 표시할 데이터를 가져오기 요청이 트리거될 때), 데이터 요청이 완료된 후 다음 상태가 줄로 사라집니다:
      • 행 선택
      • 행 확장/축소
      • 행 편집
      • 행 고정
    • 원격 데이터 시나리오에서는 격자primaryKey에 set,eventrowSelectionChanging.oldSelection 인자가 현재 데이터 뷰 밖에 있는 행의 전체 행 데이터 객체를 포함하지 않습니다. 이 경우 객체는rowSelectionChanging.oldSelection 필드 속성 중 하나primaryKey만 포함합니다. 나머지 행들은 현재 데이터 뷰에 위치해 있으며,rowSelectionChanging.oldSelection 전체 행 데이터를 포함하게 됩니다.

    API References

    Additional Resources

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