Close
Angular React Web Components Blazor React
Premium

React Hierarchical Grid のリモート データ操作

デフォルトで、IgrHierarchicalGrid は独自のロジックを使用してデータ操作を実行します。

リモート仮想化

IgrHierarchicalGrid は、データ チャンクがリモート サービスから要求されるシナリオをサポートし、内部で使用される ForOf ディレクティブで実装された動作を公開します。

この機能を使用するには、取得した引数に基づいて適切な要求を実行するために DataPreLoad 出力にサブスクライブし、サービスから送信される相対する情報とパブリック IgrHierarchicalGridTotalItemCount プロパティを設定する必要があります。

データを要求する際に StartIndex および ChunkSize プロパティを提供する IForOfState インターフェイスを使用できます。

最初の ChunkSize は常に 0 で、特定のアプリケーション シナリオに基づいて設定する必要があります。

リモートの仮想化デモ

一意の列値ストラテジ

const BASE_URL = `https://data-northwind.indigo.design/`;
const CUSTOMERS_URL = `${BASE_URL}Customers/GetCustomersWithPage`;

export class RemoteService {

    public static getCustomersDataWithPaging(pageIndex?: number, pageSize?: number) {
        return fetch(this.buildUrl(CUSTOMERS_URL, pageIndex, pageSize))
        .then((result) => result.json());
    }

    public static getHierarchyDataById(parentEntityName: string, parentId: string, childEntityName: string) {
        return fetch(`${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}`;
    }
}
  • IgrColumn - それぞれの列インスタンス。
  • FilteringExpressionsTree - フィルタリング式ツリー。各列に基づいて削減されます。
  • Done - サーバーから取得されたときに、新しく生成された列値で呼び出されるコールバック。
  <IgrHierarchicalGrid
          ref={hierarchicalGrid}
          data={data}
          pagingMode="remote"
          primaryKey="customerId"
          height="600px"
        >
          <IgrPaginator
            perPage={perPage}
            ref={paginator}
            onPageChange={onPageNumberChange}
            onPerPageChange={onPageSizeChange}
          ></IgrPaginator>
          ...
          <IgrRowIsland
            childDataKey="Orders"
            primaryKey="orderId"
            onGridCreated={onCustomersGridCreatedHandler}>
            ...

            <IgrRowIsland
              childDataKey="Details"
              primaryKey="productId"
              onGridCreated={onOrdersGridCreatedHandler}>
              ...
            </IgrRowIsland>
          </IgrRowIsland>
        </IgrHierarchicalGrid>

then set up the state:

  const hierarchicalGrid = useRef<IgrHierarchicalGrid>(null);
  const paginator = useRef<IgrPaginator>(null);

  const [data, setData] = useState([]);
  const [page, setPage] = useState(0);
  const [perPage, setPerPage] = useState(15);
  const [isLoading, setIsLoading] = useState(true);

  useEffect(() => {
    loadGridData(page, perPage);
  }, [page, perPage]);

next set up the method for loading the data:

  function loadGridData(pageIndex?: number, pageSize?: number) {
    // Set loading state
    setIsLoading(true);

    // Fetch data
    RemoteService.getCustomersDataWithPaging(pageIndex, pageSize)
      .then((response: CustomersWithPageResponseModel) => {
        setData(response.items);
        // Stop loading when data is retrieved
        setIsLoading(false);
        paginator.current.totalRecords = response.totalRecordsCount;
      })
      .catch((error) => {
        console.error(error.message);
        setData([]);
        // Stop loading even if error occurs. Prevents endless loading
        setIsLoading(false);
      })
  }

開発者は、IgrColumnFilteringExpressionsTree 引数によって提供される情報に基づいて、必要な一意の列値を手動で生成し、Done コールバックを呼び出すことができます。

  function gridCreated(event: IgrGridCreatedEventArgs, parentKey: string) {
    const context = event.detail;
    context.grid.isLoading = true;

    const parentId: string = context.parentID;
    const childDataKey: string = context.owner.childDataKey;

    RemoteService.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();
      });
  }

  const onCustomersGridCreatedHandler = (e: IgrGridCreatedEventArgs) => {
    gridCreated(e, "Customers")
  };

  const onOrdersGridCreatedHandler = (e: IgrGridCreatedEventArgs) => {
    gridCreated(e, "Orders")
  };

For further reference please check the full sample bellow:

Grid Remote Paging Demo

グリッド リモート ページングのデモ

まず、グリッドにデータを読み込む必要があります。タイミングの問題を回避するには、グリッドが描画された後に実行することをお勧めします。

その後は、ページング イベントをカスタム メソッドにバインドするだけで、リモート ページングが設定されます。

API リファレンス

IgrHierarchicalGrid
IgrPaginator

グリッド リモート ページングのデモ

また、データを読み込む方法を設定し、それに応じて UI を更新する必要があります。

最後に、階層グリッドの実際の階層レベルの背後にある動作を処理する必要があります。