Web Components 계층적 그리드 원격 데이터 작업
기본적으로 는 IgcHierarchicalGridComponent 데이터 작업을 수행하기 위해 자체 논리를 사용합니다.
이러한 작업을 원격으로 수행하고 에 의해 노출되는 특정 입력 및 이벤트를 활용하여 결과 데이터를 에 IgcHierarchicalGridComponent 공급할 수 있습니다 IgcHierarchicalGridComponent.
Remote Paging
export class RemotePagingService {
public static BASE_URL = 'https://data-northwind.indigo.design/';
public static CUSTOMERS_URL = `${RemotePagingService.BASE_URL}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));
}
public static getHierarchyDataById(parentEntityName: string, parentId: string, childEntityName: string) {
return fetch(`${RemotePagingService.BASE_URL}${parentEntityName}/${parentId}/${childEntityName}`)
.then((result) => result.json());
}
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}`;
}
}
서비스를 선언한 후 구성 및 데이터 구독을 담당할 구성 요소를 만들어야 합니다 IgcHierarchicalGridComponent.
먼저 페이지와 페이지당 표시되는 레코드의 양을 변경할 때 원격 서비스가 올바른 양의 데이터를 가져올 수 있도록 관련 이벤트에 바인딩해야 합니다
constructor() {
this.hierarchicalGrid = document.getElementById("hGrid") as IgcHierarchicalGridComponent;
this.pager = document.getElementById('paginator') as IgcPaginatorComponent;
const ordersRowIsland = document.getElementById("ordersRowIsland") as IgcRowIslandComponent;
const orderDetailsRowIsland = document.getElementById("orderDetailsRowIsland") as IgcRowIslandComponent;
ordersRowIsland.paginatorTemplate = this.webHierarchicalGridPaginatorTemplate;
orderDetailsRowIsland.paginatorTemplate = this.webHierarchicalGridPaginatorTemplate;
this._bind = () => {
window.addEventListener("load", () => {
this.pager.perPage = this._perPage;
this.loadCustomersData(this.page,this.perPage);
});
this.pager.addEventListener("perPageChange", ((args: CustomEvent<any>) => {
this.perPage = args.detail;
this.loadCustomersData(this.page, this.perPage);
}) as EventListener);
this.pager.addEventListener("pageChange", ((args: CustomEvent<any>) => {
this.page = args.detail;
this.loadCustomersData(this.page, this.perPage);
}) as EventListener);
ordersRowIsland.addEventListener("gridCreated", (event: any) => {
this.gridCreated(event, "Customers");
});
orderDetailsRowIsland.addEventListener("gridCreated", (event: any) => {
this.gridCreated(event, "Orders");
});
}
this._bind();
}
또한 데이터를 로드하는 방법을 설정하고 그에 따라 UI를 업데이트해야 합니다.
private updateUI(): void {
if (this.hierarchicalGrid && this.data) { // Check if grid and data are available
this.hierarchicalGrid.data = this.data;
}
}
private loadCustomersData(pageIndex?: number, pageSize?: number): void {
this.hierarchicalGrid.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.hierarchicalGrid.isLoading = false;
this.updateUI(); // Update the UI after receiving data
})
.catch((error) => {
console.error(error.message);
this.hierarchicalGrid.data = [];
this.hierarchicalGrid.isLoading = false;
this.updateUI();
})
}
마지막으로 Hierarchical Gird의 실제 계층 수준 뒤에 있는 동작을 처리해야 합니다
public gridCreated(event: CustomEvent<IgcGridCreatedEventArgs>, parentKey: string) {
const context = event.detail;
const parentId: string = context.parentID;
const childDataKey: string = context.owner.childDataKey;
context.grid.isLoading = true;
RemotePagingService.getHierarchyDataById(parentKey, parentId, childDataKey)
.then((data: any) => {
context.grid.data = data;
context.grid.isLoading = false;
context.grid.markForCheck();
})
.catch((error) => {
console.error(error.message);
context.grid.data = [];
context.grid.isLoading = false;
context.grid.markForCheck();
});
}
public webHierarchicalGridPaginatorTemplate = () => {
return html `
<igc-paginator
id="islandPaginator">
</igc-paginator>`
}
자세한 내용은 아래 데모를 확인하십시오.
Grid Remote Paging Demo
Known Issues and Limitations
- 그리드에
primaryKey설정되지 않고 원격 데이터 시나리오가 활성화된 경우(그리드에 표시할 데이터를 검색하기 위해 원격 서버에 대한 페이징, 정렬, 필터링, 스크롤 트리거 요청 시) 행은 데이터 이후 다음 상태를 잃습니다. 요청이 완료되었습니다:
- 행 선택
- 행 확장/축소
- 행 편집
- 행 고정
API References
Additional Resources
우리 커뮤니티는 활동적이며 항상 새로운 아이디어를 환영합니다.