Tree Grid (ツリー グリッド) ロードオンデマンド
Ignite UI for Web Components ツリー グリッド は、サーバーから最小限のデータのみ取得してレンダリングされるため、ユーザーにすばやくデータを表示できます。その後、ユーザーが行を展開した後にのみ、その特定の親行の子がロードされます。このメカニズムは、ロードオンデマンドであらゆるリモートデータとの設定が簡単にできます。
Web Components Tree Grid ロードオンデマンド例
export class EmployeesFlatDataItem {
public constructor (init: Partial<EmployeesFlatDataItem> ) {
Object .assign(this , init);
}
public Age: number ;
public HireDate: string ;
public ID: number ;
public Name: string ;
public Phone: string ;
public OnPTO: boolean ;
public ParentID: number ;
public Title: string ;
public hasEmployees: boolean ;
}
export class EmployeesFlatData extends Array <EmployeesFlatDataItem > {
public constructor ( ) {
super ();
this .push(new EmployeesFlatDataItem(
{
Age : 55 ,
HireDate : `2008, 3, 20` ,
ID : 1 ,
Name : `Johnathan Winchester` ,
Phone : `0251-031259` ,
OnPTO : false ,
ParentID : -1 ,
Title : `Development Manager`
}));
this .push(new EmployeesFlatDataItem(
{
Age : 42 ,
HireDate : `2014, 1, 22` ,
ID : 4 ,
Name : `Ana Sanders` ,
Phone : `(21) 555-0091` ,
OnPTO : true ,
ParentID : -1 ,
Title : `CEO`
}));
this .push(new EmployeesFlatDataItem(
{
Age : 49 ,
HireDate : `2014, 1, 22` ,
ID : 18 ,
Name : `Victoria Lincoln` ,
Phone : `(071) 23 67 22 20` ,
OnPTO : true ,
ParentID : -1 ,
Title : `Accounting Manager`
}));
this .push(new EmployeesFlatDataItem(
{
Age : 61 ,
HireDate : `2010, 1, 1` ,
ID : 10 ,
Name : `Yang Wang` ,
Phone : `(21) 555-0091` ,
OnPTO : false ,
ParentID : -1 ,
Title : `Localization Manager`
}));
this .push(new EmployeesFlatDataItem(
{
Age : 43 ,
HireDate : `2011, 6, 3` ,
ID : 3 ,
Name : `Michael Burke` ,
Phone : `0452-076545` ,
OnPTO : true ,
ParentID : 1 ,
Title : `Senior Software Developer`
}));
this .push(new EmployeesFlatDataItem(
{
Age : 29 ,
HireDate : `2009, 6, 19` ,
ID : 2 ,
Name : `Thomas Anderson` ,
Phone : `(14) 555-8122` ,
OnPTO : false ,
ParentID : 1 ,
Title : `Senior Software Developer`
}));
this .push(new EmployeesFlatDataItem(
{
Age : 31 ,
HireDate : `2014, 8, 18` ,
ID : 11 ,
Name : `Monica Reyes` ,
Phone : `7675-3425` ,
OnPTO : false ,
ParentID : 1 ,
Title : `Software Development Team Lead`
}));
this .push(new EmployeesFlatDataItem(
{
Age : 35 ,
HireDate : `2015, 9, 17` ,
ID : 6 ,
Name : `Roland Mendel` ,
Phone : `(505) 555-5939` ,
OnPTO : false ,
ParentID : 11 ,
Title : `Senior Software Developer`
}));
this .push(new EmployeesFlatDataItem(
{
Age : 44 ,
HireDate : `2009, 10, 11` ,
ID : 12 ,
Name : `Sven Cooper` ,
Phone : `0695-34 67 21` ,
OnPTO : true ,
ParentID : 11 ,
Title : `Senior Software Developer`
}));
this .push(new EmployeesFlatDataItem(
{
Age : 44 ,
HireDate : `2014, 4, 4` ,
ID : 14 ,
Name : `Laurence Johnson` ,
Phone : `981-443655` ,
OnPTO : false ,
ParentID : 4 ,
Title : `Director`
}));
this .push(new EmployeesFlatDataItem(
{
Age : 25 ,
HireDate : `2017, 11, 9` ,
ID : 5 ,
Name : `Elizabeth Richards` ,
Phone : `(2) 283-2951` ,
OnPTO : true ,
ParentID : 4 ,
Title : `Vice President`
}));
this .push(new EmployeesFlatDataItem(
{
Age : 39 ,
HireDate : `2010, 3, 22` ,
ID : 13 ,
Name : `Trevor Ashworth` ,
Phone : `981-443655` ,
OnPTO : true ,
ParentID : 5 ,
Title : `Director`
}));
this .push(new EmployeesFlatDataItem(
{
Age : 44 ,
HireDate : `2014, 4, 4` ,
ID : 17 ,
Name : `Antonio Moreno` ,
Phone : `(505) 555-5939` ,
OnPTO : false ,
ParentID : 18 ,
Title : `Senior Accountant`
}));
this .push(new EmployeesFlatDataItem(
{
Age : 50 ,
HireDate : `2007, 11, 18` ,
ID : 7 ,
Name : `Pedro Rodriguez` ,
Phone : `035-640230` ,
OnPTO : false ,
ParentID : 10 ,
Title : `Senior Localization Developer`
}));
this .push(new EmployeesFlatDataItem(
{
Age : 27 ,
HireDate : `2016, 2, 19` ,
ID : 8 ,
Name : `Casey Harper` ,
Phone : `0342-023176` ,
OnPTO : true ,
ParentID : 10 ,
Title : `Senior Localization`
}));
this .push(new EmployeesFlatDataItem(
{
Age : 25 ,
HireDate : `2017, 11, 9` ,
ID : 15 ,
Name : `Patricia Simpson` ,
Phone : `069-0245984` ,
OnPTO : false ,
ParentID : 7 ,
Title : `Localization Intern`
}));
this .push(new EmployeesFlatDataItem(
{
Age : 39 ,
HireDate : `2010, 3, 22` ,
ID : 9 ,
Name : `Francisco Chang` ,
Phone : `(91) 745 6200` ,
OnPTO : false ,
ParentID : 7 ,
Title : `Localization Intern`
}));
this .push(new EmployeesFlatDataItem(
{
Age : 25 ,
HireDate : `2018, 3, 18` ,
ID : 16 ,
Name : `Peter Lewis` ,
Phone : `069-0245984` ,
OnPTO : true ,
ParentID : 7 ,
Title : `Localization Intern`
}));
}
}
ts コピー import 'igniteui-webcomponents-grids/grids/combined' ;
import { IgcTreeGridComponent } from 'igniteui-webcomponents-grids/grids' ;
import { EmployeesFlatDataItem, EmployeesFlatData } from './EmployeesFlatData' ;
import "igniteui-webcomponents-grids/grids/themes/light/bootstrap.css" ;
export class Sample {
constructor ( ) {
var treeGrid = document .getElementById('treeGrid' ) as IgcTreeGridComponent;
treeGrid.expansionDepth = 0 ;
const rootData = [...this.employeesFlatData].filter(x => x.ParentID == -1 );
treeGrid.data = rootData;
(treeGrid as any ).loadChildrenOnDemand = (parentID: any , done: (children: any []) => void ) => {
this .getData(parentID, (children ) => done(children));
};
}
public getData (parentID: any , done: (children: any []) => void ) {
setTimeout (() => {
const data = [...this.employeesFlatData];
const children = data.filter((r ) => r.ParentID === parentID);
children.forEach((r ) => r.hasEmployees = data.some((c ) => c.ParentID === r.ID));
done(children);
}, 1000 );
}
private _employeesFlatData: EmployeesFlatData = null ;
public get employeesFlatData (): EmployeesFlatData {
if (this ._employeesFlatData == null )
{
this ._employeesFlatData = new EmployeesFlatData();
}
return this ._employeesFlatData;
}
}
new Sample();
ts コピー <!DOCTYPE html >
<html >
<head >
<title > Sample | Ignite UI | Web Components | infragistics</title >
<meta charset ="UTF-8" />
<link rel ="shortcut icon" href ="https://static.infragistics.com/xplatform/images/browsers/wc.png" >
<link rel ="stylesheet" href ="https://fonts.googleapis.com/icon?family=Material+Icons" />
<link rel ="stylesheet" href ="https://fonts.googleapis.com/css?family=Kanit&display=swap" />
<link rel ="stylesheet" href ="https://fonts.googleapis.com/css?family=Titillium Web" />
<link rel ="stylesheet" href ="https://static.infragistics.com/xplatform/css/samples/shared.v8.css" />
<link rel ="stylesheet" href ="/src/index.css" type ="text/css" />
</head >
<body >
<div id ="root" >
<div class ="container sample" >
<div class ="container fill" >
<igc-tree-grid
auto-generate ="false"
name ="treeGrid"
id ="treeGrid"
id ="treeGrid"
primary-key ="ID"
foreign-key ="ParentID" >
<igc-column
field ="Name"
data-type ="string"
sortable ="true"
editable ="true"
resizable ="true" >
</igc-column >
<igc-column
field ="Title"
header ="Job Title"
data-type ="string"
sortable ="true"
editable ="true"
resizable ="true" >
</igc-column >
<igc-column
field ="Age"
data-type ="number"
sortable ="true"
editable ="true"
resizable ="true" >
</igc-column >
</igc-tree-grid >
</div >
</div >
</div >
<% if (false) { %><script src ="src/index.ts" > </script > <% } %>
</body >
</html >
html コピー
このサンプルが気に入りましたか? 完全な Ignite UI for Web Componentsツールキットにアクセスして、すばやく独自のアプリの作成を開始します。無料でダウンロードできます。
使用方法
ロードオンデマンド機能は、ツリーグリッド データソースの両方のタイプ (主キーと外部キー、または子コレクション) と互換性があります。ツリー グリッドにルート レベルのデータをロードし、いずれかのデータソース タイプに必要なキーを指定するだけです。ツリーグリッドは、ユーザーが行を展開したときに子行をロードするためのコールバック入力プロパティ LoadChildrenOnDemand
を提供します。
<igc-tree-grid id ="treeGrid" > </igc-tree-grid >
html
constructor ( ) {
var treeGrid = document .getElementById("treeGrid" ) as IgcTreeGridComponent;
treeGrid.data = this .employeesFlatData;
treeGrid.loadChildrenOnDemand = (parentID: any , done: (children: any []) => void ) => {
this .getData(parentID, (children ) => done(children));
};
}
ts
LoadChildrenOnDemand コールバックは、2 つのパラメーターを提供します:
parentID - 展開されている親行の ID。
done - 子がサーバーから取得されたときに子と共に呼び出されるコールバック。
public loadChildren = (parentID: any , done: (children: any []) => void ) => {
this .getData(parentID, (children ) => done(children));
}
typescript
ユーザーが展開アイコンをクリックすると、ロード アイコンに変わります。done コールバックが呼び出されると、読み込みインジケーターが消え、子が読み込まれます。ツリーグリッドは子を基になるデータソースに追加し、必要なキーを自動的に設定します。
行がその展開前に子を持つかどうかについての情報を提供する方法がある場合は、HasChildrenKey 入力プロパティを使用できます。このようにして、展開インジケータを表示するかどうかを示すデータオブジェクトからブール値プロパティを提供できます。
<igc-tree-grid id ="treeGrid" primary-key ="ID" foreign-key ="ParentID" has-children-key ="hasEmployees" > </igc-tree-grid >
html
HasChildrenKey プロパティを設定する必要はありません。指定しなかった場合は、各行に展開インジケーターが表示されます。子を持たない行を展開した後も、未定義または空の配列で done コールバックを呼び出す必要があります。この場合、ロード インジケーターが消えた後に展開ンジケータは表示されません。
独自のカスタム ロード インジケーターを提供する場合は、RowLoadingIndicatorTemplate オプションを使用してカスタム テンプレートを設定できます。以下のコードは設定方法を示します:
constructor ( ) {
var treeGrid = document .getElementById("treeGrid" ) as IgcTreeGridComponent;
treeGrid.data = this .employeesFlatData;
treeGrid.rowLoadingIndicatorTemplate = this .rowLoadingTemplate;
treeGrid.loadChildrenOnDemand = (parentID: any , done: (children: any []) => void ) => {
this .getData(parentID, (children ) => done(children));
};
}
public rowLoadingTemplate ( ) {
return html`<igc-icon name ="loop" collection ="material" > </igc-icon > ` ;
}
ts
API リファレンス
その他のリソース
コミュニティに参加して新しいアイデアをご提案ください。