Web Components 그리드 원격 데이터 운영

    기본적으로 IgcGridComponent는 데이터 작업을 수행하기 위해 자체 로직을 사용합니다.

    IgcGridComponent에 의해 노출되는 특정 입력 및 이벤트를 활용하여 이러한 작업을 원격으로 수행하고 결과 데이터를 IgcGridComponent에 공급할 수 있습니다.

    Infinite Scroll

    끝점에서 청크로 데이터를 가져와야 하는 시나리오에 널리 사용되는 디자인은 소위 무한 스크롤입니다. 데이터 그리드의 경우 최종 사용자가 맨 아래까지 스크롤하면 로드된 데이터가 지속적으로 증가하는 것이 특징입니다. 다음 단락에서는 사용 가능한 API를 사용하여 IgcGridComponent에서 무한 스크롤을 쉽게 달성하는 방법을 설명합니다.

    무한 스크롤을 구현하려면 데이터를 청크로 가져와야 합니다. 이미 가져온 데이터는 로컬에 저장되어야 하며 청크의 길이와 청크 수를 결정해야 합니다. 또한 그리드에서 마지막으로 표시되는 데이터 행 인덱스를 추적해야 합니다. 이런 방식으로 StartIndexChunkSize 속성을 사용하면 사용자가 위로 스크롤하여 이미 가져온 데이터를 표시해야 하는지 아니면 아래로 스크롤하여 끝점에서 더 많은 데이터를 가져와야 하는지 결정할 수 있습니다.

    가장 먼저 할 일은 데이터의 첫 번째 청크를 가져오는 것입니다. totalItemCount이 속성을 설정하면 그리드에서 스크롤 막대의 크기를 올바르게 조정할 수 있으므로 중요합니다.

    또한 그리드가 현재 로드된 청크가 아닌 다른 청크를 표시하려고 할 때 그리드에 필요한 데이터를 제공할 수 있도록 출력을 구독 DataPreLoad 해야 합니다. 이벤트 처리기에서 새 데이터를 가져올지 아니면 이미 로컬에 캐시된 데이터를 반환할지 여부를 결정해야 합니다.

    Infinite Scroll Demo

    EXAMPLE
    NwindData.ts
    NwindService.ts
    TS
    HTML
    CSS

    Like this sample? Get access to our complete Ignite UI for Web Components toolkit and start building your own apps in minutes. Download it for free.

    Remote Paging

    페이징 기능은 원격 데이터로 작동할 수 있습니다. 이를 시연하기 위해 먼저 데이터 가져오기를 담당할 서비스를 선언하겠습니다. 페이지 수를 계산하려면 모든 데이터 항목의 수가 필요합니다. 이 로직은 우리 서비스에 추가될 예정입니다.

    export class RemotePagingService {
        public static CUSTOMERS_URL = `https://data-northwind.indigo.design/Customers/GetCustomersWithPage`;
        constructor() {}
    
        public static getDataWithPaging(pageIndex?: number, pageSize?: number) {
            return fetch(RemotePagingService.buildUrl(RemotePagingService.CUSTOMERS_URL, pageIndex, pageSize))
            .then((result) => result.json())
            .catch((error) => console.error(error.message));
        }
        
        private static buildUrl(baseUrl: string, pageIndex?: number, pageSize?: number) {
            let qS = "";
            if (baseUrl) {
                    qS += `${baseUrl}`;
            }
    
            // Add pageIndex and size to the query string if they are defined
            if (pageIndex !== undefined) {
                qS += `?pageIndex=${pageIndex}`;
                if (pageSize !== undefined) {
                    qS += `&size=${pageSize}`;
                }
            } else if (pageSize !== undefined) {
                qS += `?perPage=${pageSize}`;
            }
    
            return `${qS}`;
        }
    }
    ts

    서비스를 선언한 후 구성 및 데이터 구독을 담당 IgcGridComponent 할 구성 요소를 만들어야 합니다.

    먼저 페이지와 페이지당 표시되는 레코드의 양을 변경할 때 원격 서비스가 올바른 양의 데이터를 가져올 수 있도록 관련 이벤트에 바인딩해야 합니다

      constructor() {
          this.grid = document.getElementById('grid') as IgcGridComponent;
          this.pager = document.getElementById('paginator') as IgcPaginatorComponent;
          
          this._bind = () => {
            window.addEventListener("load", () => {
              this.loadData(this.page,this.perPage);
            });
    
            this.pager.addEventListener("perPageChange", ((args: CustomEvent<any>) => {
              this.perPage = args.detail;
              this.loadData(this.page, this.perPage);
            }) as EventListener);
    
            this.pager.addEventListener("pageChange", ((args: CustomEvent<any>) => {
              this.page = args.detail;
              this.loadData(this.page, this.perPage);
            }) as EventListener);
          }
    
          this._bind();
      }
    ts

    또한 데이터를 로드하는 방법을 설정하고 그에 따라 UI를 업데이트해야 합니다.

      private loadData(pageIndex?: number, pageSize?: number): void {
        this.grid.isLoading = true;
        
        RemotePagingService.getDataWithPaging(pageIndex,pageSize)
        .then((response: CustomersWithPageResponseModel) => {
          this.totalRecordsCount = response.totalRecordsCount;
          this.pager.perPage = pageSize;
          this.pager.totalRecords = this.totalRecordsCount;
          this.page = response.pageNumber;
          this.data = response.items;
          this.grid.isLoading = false;
          this.updateUI(); // Update the UI after receiving data
        })
        .catch((error) => {
          console.error(error.message);
          // Stop loading even if error occurs. Prevents endless loading
          this.grid.isLoading = false;
          this.updateUI();
        })
      }
    
        private updateUI(): void {
        if (this.grid && this.data) { // Check if grid and data are available
            this.grid.data = this.data;
        }
      }
    ts

    자세한 내용은 아래 데모를 확인하십시오.

    Grid Remote Paging Demo

    EXAMPLE
    CustomersWithPageResponseModel.ts
    RemotePagingService.ts
    TS
    HTML
    CSS

    Ignite UI for Web Components | CTA Banner

    Known Issues and Limitations

    • 그리드에 PrimaryKey 설정되어 있지 않고 원격 데이터 시나리오가 활성화된 경우(그리드에 표시할 데이터를 검색하기 위해 원격 서버에 대한 페이징, 정렬, 필터링, 스크롤 트리거 요청 시) 행은 데이터 이후 다음 상태를 잃게 됩니다. 요청이 완료되었습니다:
    • 행 선택
    • 행 확장/축소
    • 행 편집
    • 행 고정

    API References

    Additional Resources

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