React Hierarchical Grid 仮想化とパフォーマンス
Ignite UI for React の IgrHierarchicalGrid
コントロールは水平および垂直方向にコンテンツを仮想化します。
React Hierarchical Grid 仮想化とパフォーマンスの例
const URL = `https://data-northwind.indigo.design/` ;
export function getData (dataState: any ): any {
return fetch(buildUrl(dataState))
.then((result ) => result.json());
}
function buildUrl (dataState: any ) {
let qS = "" ;
if (dataState) {
if (dataState.rootLevel) {
qS += `${dataState.key} ` ;
} else {
qS += `${dataState.parentKey} /${dataState.parentID} /${dataState.key} ` ;
}
}
return `${URL} ${qS} ` ;
}
ts コピー import React , { useEffect, useRef } from "react" ;
import ReactDOM from "react-dom/client" ;
import "./index.css" ;
import { IgrGridCreatedEventArgs, IgrHierarchicalGridModule } from "@infragistics/igniteui-react-grids" ;
import { IgrHierarchicalGrid, IgrColumn, IgrRowIsland } from "@infragistics/igniteui-react-grids" ;
import "@infragistics/igniteui-react-grids/grids/combined" ;
import "@infragistics/igniteui-react-grids/grids/themes/light/bootstrap.css" ;
import { getData } from "./RemoteService" ;
IgrHierarchicalGridModule.register();
export default function App() {
const hierarchicalGrid = useRef<IgrHierarchicalGrid > (null );
useEffect(() => {
hierarchicalGrid.current.isLoading = true ;
getData({ parentID: null , rootLevel: true , key: "Customers" }).then(
(data: any ) => {
hierarchicalGrid.current.isLoading = false ;
hierarchicalGrid.current.data = data;
hierarchicalGrid.current.markForCheck();
}
);
}, []);
function gridCreated(
rowIsland: IgrRowIsland,
event: IgrGridCreatedEventArgs,
_parentKey: string
) {
const context = event.detail;
const dataState = {
key: rowIsland.childDataKey,
parentID: context.parentID,
parentKey: _parentKey,
rootLevel: false ,
};
context.grid.isLoading = true ;
getData(dataState).then((data: any []) => {
context.grid.isLoading = false ;
context.grid.data = data;
context.grid.markForCheck();
});
}
return (
<div className ="container sample ig-typography" >
<div className ="container fill" >
<IgrHierarchicalGrid
ref ={hierarchicalGrid}
primaryKey ="customerId"
height ="600px"
>
<IgrColumn field ="customerId" hidden ={true} > </IgrColumn >
<IgrColumn field ="companyName" header ="Company Name" > </IgrColumn >
<IgrColumn field ="contactName" header ="Contact Name" > </IgrColumn >
<IgrColumn field ="contactTitle" header ="Contact Title" > </IgrColumn >
<IgrColumn field ="address.country" header ="Country" > </IgrColumn >
<IgrColumn field ="address.phone" header ="Phone" > </IgrColumn >
<IgrRowIsland
childDataKey ="Orders"
primaryKey ="orderId"
gridCreated ={(
rowIsland: IgrRowIsland ,
e: IgrGridCreatedEventArgs
) => gridCreated(rowIsland, e, "Customers" )}
>
<IgrColumn field ="orderId" hidden ={true} > </IgrColumn >
<IgrColumn field ="shipAddress.country" header ="Ship Country" > </IgrColumn >
<IgrColumn field ="shipAddress.city" header ="Ship City" > </IgrColumn >
<IgrColumn field ="shipAddress.street" header ="Ship Address" > </IgrColumn >
<IgrColumn field ="orderDate" header ="Order Date" dataType ="date" > </IgrColumn >
<IgrRowIsland
childDataKey ="Details"
primaryKey ="productId"
gridCreated ={(
rowIsland: IgrRowIsland ,
e: IgrGridCreatedEventArgs
) => gridCreated(rowIsland, e, "Orders" )}
>
<IgrColumn field ="productId" hidden ={true} > </IgrColumn >
<IgrColumn field ="quantity" header ="Quantity" > </IgrColumn >
<IgrColumn field ="unitPrice" header ="Unit Price" > </IgrColumn >
<IgrColumn field ="discount" header ="Discount" > </IgrColumn >
</IgrRowIsland >
</IgrRowIsland >
</IgrHierarchicalGrid >
</div >
</div >
);
}
const root = ReactDOM.createRoot (document.getElementById("root" ));
root.render (<App /> );
tsx コピー
このサンプルが気に入りましたか? 完全な Ignite UI for Reactツールキットにアクセスして、すばやく独自のアプリの作成を開始します。無料でダウンロードできます。
仮想化の有効化
IgrHierarchicalGrid
は、ビューポートに表示されているデータのみを描画し、ユーザーがスクロール時に表示データを切り替えた際に、DOM 描画およびメモリ使用を最適化します。IgrHierarchicalGrid
の width
および height
のデフォルト値は 100%
です。コンテンツが利用可能なスペースにフィットせず、垂直方向または水平方向にスクロールバーが必要な場合に仮想化が有効になります。
ただし、IgrHierarchicalGrid
の width
または height
を明示的に null
値に設定できます。つまり、関連するディメンションが項目の合計サイズに基づいて決定されます。スクロールバーが表示されず、すべての項目が相対するディメンション (width
が null
値の場合は列で、height
が null
値の場合は行) に描画されます。
データのサイズは以下によって決定されます。
ディメンションを設定せずにグリッドでデフォルト動作を適用する場合、ほとんどの場合は望ましいレイアウトになります。列幅は列カウント、幅が設定された列、および IgrHierarchicalGrid
コンテナの計算幅に基づいて決定されます。グリッドは、割り当てる幅が 136px 未満になる以外はすべての列を利用可能なスペースに合わせようとします。その場合、割り当てられない幅を持つ列は 136px の最小幅に設定され、水平方向スクロールバーが表示されます。グリッドは水平方向に仮想化されます。
列幅をパーセンテージ (%) で明示的に設定する場合、ほとんどの場合に水平スクロールバーがない水平方向に仮想化されないグリッドを作成します。
仮想化の制限
Mac OS で 「Show scrollbars only when scrolling」システム オプションを true (デフォルト値) に設定した場合、水平スクロールバーが表示されません。これは、IgrHierarchicalGrid
の行コンテナーで、overflow が hidden に設定されているためです。オプションを「Always」に変更するとスクロールが表示されます。
FAQ
仮想化がで Hierarchical Grid でディメンションを設定する必要があるのはなぜですか?
描画する前にコンテナーおよび項目のサイズの情報がない場合に IgrHierarchicalGrid
でランダムな位置にスクロールすると、スクロールバーの幅や高さの設定、表示項目の決定で誤りが発生します。ディメンションの推測がスクロールバーの誤操作となり、ユーザー エクスペリエンスを低下させます。そのため、仮想化を有効にするには、関連ディメンションを設定する必要があります。
API リファレンス
その他のリソース
コミュニティに参加して新しいアイデアをご提案ください。