グリッド:ツリーグリッド

データ項目に子項目のコレクションが含まれている場合、FlexGridのchildItemsPathを使用してデータをツリーとして表示できます。例えば、「children」プロパティを持つ「person」オブジェクトのリストを考えてみましょう。「children」プロパティには、さらに多くのpersonオブジェクトの配列が含まれます。これは、均一な階層とも呼ばれます。下のグリッドは、グリッドをトップレベルの人物リストに連結し、childItemsPathプロパティを「children」に設定することで構築されています。

import 'bootstrap.css'; import '@grapecity/wijmo.styles/wijmo.css'; import './styles.css'; import * as wjGrid from '@grapecity/wijmo.grid'; // document.readyState === 'complete' ? init() : window.onload = init; // function init() { // // family tree data (homogeneous collection) var family = [ { name: 'ワシントン', children: [ { name: 'シアトル' }, { name: 'スポケーン' }, ] }, { name: 'オレゴン', children: [ { name: 'ポートランド' }, { name: 'ユージーン' }, ] }, { name: 'カリフォルニア', children: [ { name: 'ロサンゼルス' }, { name: 'サンディエゴ' }, { name: 'サンフランシスコ' } ] }, ]; // // family tree var familyGrid = new wjGrid.FlexGrid('#familyGrid', { headersVisibility: 'None', childItemsPath: 'children', itemsSource: family }); // // toggle family tree document.getElementById('asTree').addEventListener('click', function (e) { familyGrid.childItemsPath = e.target.checked ? 'children' : ''; }); // // workers tree data (heterogeneous collection) var workers = [{ name: '成宮 真紀', checks: [{ name: '1月', earnings: [ { name: '通常勤務', hours: 30.0, rate: 15.0 }, { name: '残業手当', hours: 10.0, rate: 20.0 }, { name: 'ボーナス', hours: 5.0, rate: 30.0 } ] }, { name: '2月', earnings: [ { name: '通常勤務', hours: 20.0, rate: 18.0 }, { name: '残業手当', hours: 20.0, rate: 24.0 } ] }] }, { name: '山本 雅治', checks: [{ name: '1月', earnings: [ { name: '通常勤務', hours: 30.0, rate: 15.0 }, { name: '残業手当', hours: 10.0, rate: 20.0 }, { name: 'ボーナス', hours: 5.0, rate: 30.0 } ] }, { name: '2月', earnings: [ { name: '通常勤務', hours: 20.0, rate: 18.0 }, { name: '残業手当', hours: 20.0, rate: 24.0 } ] }] }, { name: '加藤 泰江', checks: [{ name: '1月', earnings: [ { name: '通常勤務', hours: 30.0, rate: 15.0 }, { name: '残業手当', hours: 10.0, rate: 20.0 }, { name: 'ボーナス', hours: 5.0, rate: 30.0 } ] }, { name: '2月', earnings: [ { name: '通常勤務', hours: 20.0, rate: 18.0 }, { name: '残業手当', hours: 20.0, rate: 24.0 } ] }] }]; // // workers tree var workersGrid = new wjGrid.FlexGrid('#workersGrid', { headersVisibility: 'Column', childItemsPath: ['checks', 'earnings'], autoGenerateColumns: false, columns: [ { binding: 'name', header: '名前' }, { binding: 'hours', header: '勤務時間', dataType: 'Number' }, { binding: 'rate', header: '時給', dataType: 'Number' } ], itemsSource: workers, }); } <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <title>GrapeCity Wijmo FlexGrid Tree Grids</title> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <!-- SystemJS --> <script src="node_modules/systemjs/dist/system.src.js"></script> <script src="systemjs.config.js"></script> <script> System.import('./src/app'); </script> </head> <body> <div class="container-fluid"> <label for="asTree">ツリーとして表示: </label> <input id="asTree" type="checkbox" checked="checked"> <div id="familyGrid"></div> <p> また、各レベルに異なる種類の子項目のプロパティが設定されている、<em>不均一な</em>階層もあります。</p> <p> たとえば、以下のグリッドは'worker'オブジェクトのコレクションに連結されており、'worker'には'checks'リストが含まれ、'checks'には'earnings'リストが含まれます。</p> <div id="workersGrid"></div> </div> </body> </html> .wj-flexgrid { max-height: 220px; margin: 6px 0; } .wj-cell.wj-group { border: none; } .wj-cell.wj-group:not(.wj-state-selected):not(.wj-state-multi-selected) { background-color: white; } body { margin-bottom: 24px; } import 'bootstrap.css'; import '@grapecity/wijmo.styles/wijmo.css'; import './styles.css'; // import * as wjGrid from '@grapecity/wijmo.grid'; import { Component, Inject, enableProdMode, NgModule, ViewChild, AfterViewInit } from '@angular/core'; import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; import { BrowserModule } from '@angular/platform-browser'; import { WjGridModule } from '@grapecity/wijmo.angular2.grid'; import { DataService } from './app.data'; // @Component({ selector: 'app-component', templateUrl: 'src/app.component.html' }) export class AppComponent implements AfterViewInit { @ViewChild('familyGrid') familyGrid: wjGrid.FlexGrid; family: any; workers: any; // DataSvc will be passed by derived classes constructor(@Inject(DataService) private dataService: DataService) { this.family = dataService.getFamilies(); this.workers = dataService.getWorkers(); } // ngAfterViewInit() { this.familyGrid.columns[0].with = "*"; } // onAsTreeClick(e:MouseEvent) { this.familyGrid.childItemsPath = (<HTMLInputElement>e.target).checked ? 'cities' : ''; } } //\\ @NgModule({ imports: [WjGridModule, BrowserModule], declarations: [AppComponent], providers: [DataService], bootstrap: [AppComponent] }) export class AppModule { } // enableProdMode(); // Bootstrap application with hash style navigation and global services. platformBrowserDynamic().bootstrapModule(AppModule); <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <title>GrapeCity Wijmo FlexGrid Tree Grids</title> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <!-- Polyfills --> <script src="node_modules/core-js/client/shim.min.js"></script> <script src="node_modules/zone.js/dist/zone.min.js"></script> <!-- SystemJS --> <script src="node_modules/systemjs/dist/system.js"></script> <script src="systemjs.config.js"></script> <script> // workaround to load 'rxjs/operators' from the rxjs bundle System.import('rxjs').then(function (m) { System.set(SystemJS.resolveSync('rxjs/operators'), System.newModule(m.operators)); System.import('./src/app.component'); }); </script> </head> <body> <app-component></app-component> </body> </html> <div class="container-fluid"> <label for="asTree">ツリーとして表示: </label> <input id="asTree" type="checkbox" checked="checked" (click)="onAsTreeClick($event)"> <wj-flex-grid #familyGrid [itemsSource]="family" [headersVisibility]="'None'" [childItemsPath]="'cities'"> </wj-flex-grid> <p> また、各レベルに異なる種類の子項目のプロパティが設定されている、<em>不均一な</em>階層もあります。</p> <p> たとえば、以下のグリッドは'worker'オブジェクトのコレクションに連結されており、'worker'には'checks'リストが含まれ、'checks'には'earnings'リストが含まれます。</p> <wj-flex-grid #workersGrid [itemsSource]="workers" [headersVisibility]="'Column'" [childItemsPath]="['checks','earnings']" [autoGenerateColumns]=false> <wj-flex-grid-column [binding]="'name'" header="名前"></wj-flex-grid-column> <wj-flex-grid-column [binding]="'hours'" header="勤務時間" [dataType]="'Number'"></wj-flex-grid-column> <wj-flex-grid-column [binding]="'rate'" header="時給" [dataType]="'Number'"></wj-flex-grid-column> </wj-flex-grid> </div> import { Injectable } from '@angular/core'; @Injectable() export class DataService { getFamilies() { return [ { name: 'ワシントン', type: '州', population: 6971, cities: [ { name: 'シアトル', type: '都市', population: 652 }, { name: 'スポケーン', type: '都市', population: 210 }] }, { name: 'オレゴン', type: '州', population: 3930, cities: [ { name: 'ポートランド', type: '都市', population: 609 }, { name: 'ユージーン', type: '都市', population: 159 }] }, { name: 'カリフォルニア', type: '州', population: 38330, cities: [ { name: 'ロサンゼルス', type: '都市', population: 3884 }, { name: 'サンディエゴ', type: '都市', population: 1356 }, { name: 'サンフランシスコ', type: '都市', population: 837 }] } ]; } getWorkers() { return [{ name: '成宮 真紀', checks: [{ name: '1月', earnings: [ { name: '通常勤務', hours: 30.0, rate: 15.0 }, { name: '残業手当', hours: 10.0, rate: 20.0 }, { name: 'ボーナス', hours: 5.0, rate: 30.0 } ] }, { name: '2月', earnings: [ { name: '通常勤務', hours: 20.0, rate: 18.0 }, { name: '残業手当', hours: 20.0, rate: 24.0 } ] }] }, { name: '山本 雅治', checks: [{ name: '1月', earnings: [ { name: '通常勤務', hours: 30.0, rate: 15.0 }, { name: '残業手当', hours: 10.0, rate: 20.0 }, { name: 'ボーナス', hours: 5.0, rate: 30.0 } ] }, { name: '2月', earnings: [ { name: '通常勤務', hours: 20.0, rate: 18.0 }, { name: '残業手当', hours: 20.0, rate: 24.0 } ] }] }, { name: '加藤 泰江', checks: [{ name: '1月', earnings: [ { name: '通常勤務', hours: 30.0, rate: 15.0 }, { name: '残業手当', hours: 10.0, rate: 20.0 }, { name: 'ボーナス', hours: 5.0, rate: 30.0 } ] }, { name: '2月', earnings: [ { name: '通常勤務', hours: 20.0, rate: 18.0 }, { name: '残業手当', hours: 20.0, rate: 24.0 } ] }] }]; } } .wj-flexgrid { max-height: 220px; margin: 6px 0; } .wj-cell.wj-group { border: none; } .wj-cell.wj-group:not(.wj-state-selected):not(.wj-state-multi-selected) { background-color: white; } body { margin-bottom: 24px; } import "@grapecity/wijmo.styles/wijmo.css"; import "bootstrap.css"; import "./app.css"; // import * as React from 'react'; import * as ReactDOM from 'react-dom'; import * as wjcGrid from "@grapecity/wijmo.react.grid"; import { getFamilies, getWorkers } from "./data"; class App extends React.Component { constructor(props) { super(props); this.state = { family: getFamilies(), workers: getWorkers() }; } render() { return <div className="container-fluid"> <label htmlFor="asTree">ツリーとして表示: </label> <input id="asTree" type="checkbox" defaultChecked onClick={this.onAsTreeClick.bind(this)}/> <wjcGrid.FlexGrid itemsSource={this.state.family} headersVisibility="None" childItemsPath="cities" initialized={this.initialFamilayGrid.bind(this)}></wjcGrid.FlexGrid> <p> また、各レベルに異なる種類の子項目のプロパティが設定されている、<em>不均一な</em>階層もあります。</p> <p> たとえば、以下のグリッドは'worker'オブジェクトのコレクションに連結されており、'worker'には'checks'リストが含まれ、'checks'には'earnings'リストが含まれます。</p> <wjcGrid.FlexGrid itemsSource={this.state.workers} headersVisibility="Column" childItemsPath={['checks', 'earnings']}> <wjcGrid.FlexGridColumn binding="name" header="名前"></wjcGrid.FlexGridColumn> <wjcGrid.FlexGridColumn binding="hours" header="勤務時間" dataType="Number"></wjcGrid.FlexGridColumn> <wjcGrid.FlexGridColumn binding="rate" header="時給" dataType="Number"></wjcGrid.FlexGridColumn> </wjcGrid.FlexGrid> </div>; } componentDidMount() { this.familyGrid.columns[0].with = "*"; } initialFamilayGrid(grid) { this.familyGrid = grid; } onAsTreeClick(e) { this.familyGrid.childItemsPath = e.target.checked ? 'cities' : ''; } } ReactDOM.render(<App />, document.getElementById('app')); <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <title>Grapecity Wijmo OLAP Pivot Chart Overview</title> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <!-- SystemJS --> <script src="node_modules/systemjs/dist/system.src.js"></script> <script src="systemjs.config.js"></script> <script> System.import('./src/app'); </script> </head> <body> <div id="app"></div> </body> </html> .wj-flexgrid { max-height: 220px; margin: 6px 0; } .wj-cell.wj-group { border: none; } .wj-cell.wj-group:not(.wj-state-selected):not(.wj-state-multi-selected) { background-color: white; } body { margin-bottom: 24px; } export function getFamilies() { return [ { name: 'ワシントン', type: '州', population: 6971, cities: [ { name: 'シアトル', type: '都市', population: 652 }, { name: 'スポケーン', type: '都市', population: 210 } ] }, { name: 'オレゴン', type: '州', population: 3930, cities: [ { name: 'ポートランド', type: '都市', population: 609 }, { name: 'ユージーン', type: '都市', population: 159 } ] }, { name: 'カリフォルニア', type: '州', population: 38330, cities: [ { name: 'ロサンゼルス', type: '都市', population: 3884 }, { name: 'サンディエゴ', type: '都市', population: 1356 }, { name: 'サンフランシスコ', type: '都市', population: 837 } ] } ]; } export function getWorkers() { return [{ name: '成宮 真紀', checks: [{ name: '1月', earnings: [ { name: '通常勤務', hours: 30.0, rate: 15.0 }, { name: '残業手当', hours: 10.0, rate: 20.0 }, { name: 'ボーナス', hours: 5.0, rate: 30.0 } ] }, { name: '2月', earnings: [ { name: '通常勤務', hours: 20.0, rate: 18.0 }, { name: '残業手当', hours: 20.0, rate: 24.0 } ] }] }, { name: '山本 雅治', checks: [{ name: '1月', earnings: [ { name: '通常勤務', hours: 30.0, rate: 15.0 }, { name: '残業手当', hours: 10.0, rate: 20.0 }, { name: 'ボーナス', hours: 5.0, rate: 30.0 } ] }, { name: '2月', earnings: [ { name: '通常勤務', hours: 20.0, rate: 18.0 }, { name: '残業手当', hours: 20.0, rate: 24.0 } ] }] }, { name: '加藤 泰江', checks: [{ name: '1月', earnings: [ { name: '通常勤務', hours: 30.0, rate: 15.0 }, { name: '残業手当', hours: 10.0, rate: 20.0 }, { name: 'ボーナス', hours: 5.0, rate: 30.0 } ] }, { name: '2月', earnings: [ { name: '通常勤務', hours: 20.0, rate: 18.0 }, { name: '残業手当', hours: 20.0, rate: 24.0 } ] }] }]; } <template> <div class="container-fluid"> <label for="asTree">ツリーとして表示: </label> <input id="asTree" type="checkbox" checked v-on:click="onAsTreeClick"> <wj-flex-grid :items-source="family" headers-visibility="None" child-items-path="cities" :initialized="initialFamilayGrid"> </wj-flex-grid> <p> また、各レベルに異なる種類の子項目のプロパティが設定されている、<em>不均一な</em>階層もあります。</p> <p> たとえば、以下のグリッドは'worker'オブジェクトのコレクションに連結されており、'worker'には'checks'リストが含まれ、'checks'には'earnings'リストが含まれます。</p> <wj-flex-grid :items-source="workers" headers-visibility="Column" :child-items-path="['checks','earnings']"> <wj-flex-grid-column binding="name" header="名前"></wj-flex-grid-column> <wj-flex-grid-column binding="hours" header="勤務時間" data-type="Number"></wj-flex-grid-column> <wj-flex-grid-column binding="rate" header="時給" data-type="Number"></wj-flex-grid-column> </wj-flex-grid> </div> </template> <script> import "@grapecity/wijmo.styles/wijmo.css"; import "bootstrap.css"; import Vue from "vue"; import "@grapecity/wijmo.vue2.grid"; import { getFamilies, getWorkers} from "./data"; new Vue({ el: "#app", data: function() { return { family: getFamilies(), workers: getWorkers() } }, mounted: function() { this.familyGrid.columns[0].with = "*"; }, methods: { initialFamilayGrid(grid) { this.familyGrid = grid; }, onAsTreeClick(e) { this.familyGrid.childItemsPath = e.target.checked ? 'cities' : ''; } } }); </script> <style> .wj-flexgrid { max-height: 220px; margin: 6px 0; } .wj-cell.wj-group { border: none; } .wj-cell.wj-group:not(.wj-state-selected):not(.wj-state-multi-selected) { background-color: white; } body { margin-bottom: 24px; } </style> <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <title>GrapeCity Wijmo FlexGrid Tree Grids</title> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <!-- SystemJS --> <script src="node_modules/systemjs/dist/system.src.js"></script> <script src="systemjs.config.js"></script> <script> System.import('./src/app.vue'); </script> </head> <body> <div id="app"> </div> </body> </html> export function getFamilies() { return [ { name: 'ワシントン', type: '州', population: 6971, cities: [ { name: 'シアトル', type: '都市', population: 652 }, { name: 'スポケーン', type: '都市', population: 210 }] }, { name: 'オレゴン', type: '州', population: 3930, cities: [ { name: 'ポートランド', type: '都市', population: 609 }, { name: 'ユージーン', type: '都市', population: 159 }] }, { name: 'カリフォルニア', type: '州', population: 38330, cities: [ { name: 'ロサンゼルス', type: '都市', population: 3884 }, { name: 'サンディエゴ', type: '都市', population: 1356 }, { name: 'サンフランシスコ', type: '都市', population: 837 }] } ] } export function getWorkers() { return [{ name: '成宮 真紀', checks: [{ name: '1月', earnings: [ { name: '通常勤務', hours: 30.0, rate: 15.0 }, { name: '残業手当', hours: 10.0, rate: 20.0 }, { name: 'ボーナス', hours: 5.0, rate: 30.0 } ] }, { name: '2月', earnings: [ { name: '通常勤務', hours: 20.0, rate: 18.0 }, { name: '残業手当', hours: 20.0, rate: 24.0 } ] }] }, { name: '山本 雅治', checks: [{ name: '1月', earnings: [ { name: '通常勤務', hours: 30.0, rate: 15.0 }, { name: '残業手当', hours: 10.0, rate: 20.0 }, { name: 'ボーナス', hours: 5.0, rate: 30.0 } ] }, { name: '2月', earnings: [ { name: '通常勤務', hours: 20.0, rate: 18.0 }, { name: '残業手当', hours: 20.0, rate: 24.0 } ] }] }, { name: '加藤 泰江', checks: [{ name: '1月', earnings: [ { name: '通常勤務', hours: 30.0, rate: 15.0 }, { name: '残業手当', hours: 10.0, rate: 20.0 }, { name: 'ボーナス', hours: 5.0, rate: 30.0 } ] }, { name: '2月', earnings: [ { name: '通常勤務', hours: 20.0, rate: 18.0 }, { name: '残業手当', hours: 20.0, rate: 24.0 } ] }] }]; }