グリッド:編集可能なツリーグリッド

FlexGridのchildItemsPathを使用してデータをツリーとして表示すると、結果のグリッドはデフォルトで読み取り専用になります。これは、ツリー内のすべての行がGroupRowであり、グループ行がデフォルトで読み取り専用であるために発生します。ツリーを編集可能にするには、loadedRowsイベントを処理して、すべての行のisReadOnlyプロパティをfalseに設定します。

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() { // // 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', selectionMode: 'Row', childItemsPath: ['checks', 'earnings'], autoGenerateColumns: false, columns: [ { binding: 'name', header: '名前', isReadOnly: true }, { binding: 'hours', header: '勤務時間', dataType: 'Number', format: 'n2' }, { binding: 'rate', header: '時給', dataType: 'Number', format: 'n2' } ], loadedRows: function (s, e) { s.rows.forEach(function (row) { row.isReadOnly = false; }); }, beginningEdit: function (s, e) { var item = s.rows[e.row].dataItem, binding = s.columns[e.col].binding; if (!(binding in item)) { // property not on this item? e.cancel = true; // can't edit! } }, 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 Editable Tree Grid</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"> <div id="workersGrid"></div> </div> </body> </html> .wj-flexgrid { max-height: 220px; margin: 10px; } .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 } 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 { workers: any; // DataSvc will be passed by derived classes constructor(@Inject(DataService) private dataService: DataService) { this.workers = dataService.getWorkers(); } // onLoadedRows(flexGird: wjGrid.FlexGrid, e: wjGrid.FormatItemEventArgs) { flexGird.rows.forEach(function (row: wjGrid.Row) { row.isReadOnly = false; }) } // onBeginningEdit(flexGird: wjGrid.FlexGrid, e: wjGrid.CellEditEndingEventArgs) { var item = flexGird.rows[e.row].dataItem, binding = flexGird.columns[e.col].binding; if (!(binding in item)) { // property not on this item? e.cancel = true; // can't edit! } } } //\\ @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 Editable Tree Grid</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"> <wj-flex-grid #grid [itemsSource]="workers" [autoGenerateColumns]=false [headersVisibility]="'Column'" [selectionMode]="'Row'" [childItemsPath]="['checks','earnings']" (loadedRows)="onLoadedRows(grid,$event)" (beginningEdit)="onBeginningEdit(grid, $event)"> <wj-flex-grid-column [binding]="'name'" header="名前" [isReadOnly]=true></wj-flex-grid-column> <wj-flex-grid-column [binding]="'hours'" header="勤務時間" [dataType]="'Number'" [format]="'n2'"></wj-flex-grid-column> <wj-flex-grid-column [binding]="'rate'" header="時給" [dataType]="'Number'" [format]="'n2'"></wj-flex-grid-column> </wj-flex-grid> </div> import { Injectable } from '@angular/core'; @Injectable() export class DataService { 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: 10px; } .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 { getWorkers } from "./data"; class App extends React.Component { constructor(props) { super(props); this.state = { workers: getWorkers() }; } render() { return <div className="container-fluid"> <wjcGrid.FlexGrid itemsSource={this.state.workers} headersVisibility="Column" selectionMode="Row" beginningEdit={this.onBeginningEdit.bind(this)} childItemsPath={['checks', 'earnings']} initialized={this.initialWorkerGrid.bind(this)}> <wjcGrid.FlexGridColumn binding="name" header="名前" isReadOnly={true}></wjcGrid.FlexGridColumn> <wjcGrid.FlexGridColumn binding="hours" header="勤務時間" dataType="Number" format="n2"></wjcGrid.FlexGridColumn> <wjcGrid.FlexGridColumn binding="rate" header="時給" dataType="Number" format="n2"></wjcGrid.FlexGridColumn> </wjcGrid.FlexGrid> </div>; } componentDidMount() { this.workerGrid.rows.forEach((row) => { row.isReadOnly = false; }); } initialWorkerGrid(grid) { this.workerGrid = grid; } onBeginningEdit(flexGird, e) { let item = flexGird.rows[e.row].dataItem, binding = flexGird.columns[e.col].binding; if (!(binding in item)) { // property not on this item? e.cancel = true; // can't edit! } } } 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: 10px; } .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 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"> <wj-flex-grid :items-source="workers" headers-visibility="Column" :child-items-path="['checks','earnings']" selection-mode="Row" :beginning-edit="onBeginningEdit" :initialized="initialWorkerGrid"> <wj-flex-grid-column binding="name" header="名前" :is-read-only="true"></wj-flex-grid-column> <wj-flex-grid-column binding="hours" header="勤務時間" data-type="Number" format="n2"></wj-flex-grid-column> <wj-flex-grid-column binding="rate" header="時給" data-type="Number" format="n2"></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 { getWorkers} from "./data"; new Vue({ el: "#app", data: function() { return { workers: getWorkers() } }, mounted: function() { this.workerGrid.rows.forEach((row) => { row.isReadOnly = false; }); }, methods: { initialWorkerGrid(grid) { this.workerGrid = grid; }, /*onLoadedRows(flexGird, e) { flexGird.rows.forEach((row) => { row.isReadOnly = false; }); },*/ onBeginningEdit(flexGird, e) { let item = flexGird.rows[e.row].dataItem, binding = flexGird.columns[e.col].binding; if (!(binding in item)) { // property not on this item? e.cancel = true; // can't edit! } } } }); </script> <style> .wj-flexgrid { max-height: 220px; margin: 10px; } .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 Editable Tree Grid</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 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 } ] }] }]; }