グリッド:データマップ

列に値をマッピングして、セルに実際にグリッドに格納されているものとは異なる値が表示されるようにすることができます。formatItemイベントを使用してこの動作を実行できますが、FlexGridデータマップというより優れた代替方法を提供します。列のdataMapプロパティをDataMapのインスタンスに設定すると、グリッドはそれを使用して各データ項目の表示値を検索し、セル編集時に有効な項目を含むドロップダウンリストを提供します。

import 'bootstrap.css'; import '@grapecity/wijmo.styles/wijmo.css'; import './styles.css'; import '@grapecity/wijmo.input'; import { FlexGrid, DataMap } from '@grapecity/wijmo.grid'; document.readyState === 'complete' ? init() : window.onload = init; function init() { // create some random data var countries = 'アメリカ,ドイツ,イギリス,日本,スウェーデン,ノルウェー,デンマーク'.split(','); var customers = [ { id: 0, name: '成宮 真紀', address: '愛知県春日井市味美白山町 1-9-X' }, { id: 1, name: '山本 雅治', address: '福岡県粕屋郡志免町御手洗 51-X' }, { id: 2, name: '加藤 泰江', address: '茨城県牛久市下根町 1504-XX' }, { id: 3, name: '川村 匡', address: '広島県広島市西区観音新町 1-16-X' }, ]; var data = []; for (var i = 0; i < countries.length; i++) { data.push({ id: i, country: countries[i], customer: customers[i % customers.length].id, active: i % 5 != 0, downloads: Math.round(Math.random() * 200000), sales: Math.random() * 100000, expenses: Math.random() * 50000 }); } // create customer data map var customerMap = new DataMap(customers, 'id', 'name'); // show the data in a grid var theGrid = new FlexGrid('#theGrid', { alternatingRowStep: 0, autoGenerateColumns: false, columns: [ { binding: 'customer', header: '顧客', width: '1.5*', dataMap: customerMap }, { binding: 'country', header: '国', width: '*', dataMap: countries }, { binding: 'downloads', header: 'DL数', width: '*', format: 'n0' }, { binding: 'sales', header: '売上', width: '*', format: 'n0' }, { binding: 'expenses', header: '費用', width: '*', format: 'n0' } ], itemsSource: data, }); // show customers as well var theGridCustomers = new FlexGrid('#theGridCustomers', { autoGenerateColumns: false, columns: [ { binding: 'id', header: 'ID', width: 80 }, { binding: 'name', header: '名前' }, { binding: 'address', header: '住所', width: '*' }, ], itemsSource: customers, rowEditEnded: function () { let column = theGrid.getColumn('customer'); if (column) { column.dataMap = new DataMap(customers, 'id', 'name'); } theGrid.refresh(); // update customer names on the main grid } }); } <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <title>GrapeCity Wijmo FlexGrid Column DataMaps</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="theGrid"> </div> <p> 下記は顧客一覧のグリッドです。名前を編集すると、上のグリッドに変更が反映されます。</p> <div id="theGridCustomers"> </div> </div> </body> </html> .wj-flexgrid { max-height: 200px; margin: 12px 0; } import 'bootstrap.css'; import '@grapecity/wijmo.styles/wijmo.css'; import './styles.css'; // import { Component, enableProdMode, NgModule, ViewChild } from '@angular/core'; import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; import { BrowserModule } from '@angular/platform-browser'; import * as wjcGrid from '@grapecity/wijmo.grid'; import { WjGridModule } from '@grapecity/wijmo.angular2.grid'; import { WjInputModule } from '@grapecity/wijmo.angular2.input'; // @Component({ selector: 'app-component', templateUrl: 'src/app.component.html' }) export class AppComponent { data: any[]; customerMap: wjcGrid.DataMap; countries = 'アメリカ,ドイツ,イギリス,日本,スウェーデン,ノルウェー,デンマーク'.split(','); customers = [ { id: 0, name: '成宮 真紀', address: '愛知県春日井市味美白山町 1-9-X' }, { id: 1, name: '山本 雅治', address: '福岡県粕屋郡志免町御手洗 51-X' }, { id: 2, name: '加藤 泰江', address: '茨城県牛久市下根町 1504-XX' }, { id: 3, name: '川村 匡', address: '広島県広島市西区観音新町 1-16-X' }, ]; @ViewChild('mainGrid') mainGrid: wjcGrid.FlexGrid; // DataSvc will be passed by derived classes constructor() { this.data = this._getData(); this.customerMap = new wjcGrid.DataMap(this.customers, 'id', 'name'); } dataMapGridInitialized(flexgrid: wjcGrid.FlexGrid) { flexgrid.rowEditEnded.addHandler(() => { let column = this.mainGrid.getColumn('customer'); if (column) { column.dataMap = new wjcGrid.DataMap(this.customers, 'id', 'name'); } this.mainGrid.refresh(); // update customer names on the main grid }); } private _getData() { let data = []; for (let i = 0; i < this.countries.length; i++) { data.push({ id: i, country: this.countries[i], customer: this.customers[i % this.customers.length].id, active: i % 5 != 0, downloads: Math.round(Math.random() * 200000), sales: Math.random() * 100000, expenses: Math.random() * 50000 }); } return data; } } // @NgModule({ imports: [WjGridModule, WjInputModule, BrowserModule], declarations: [AppComponent], 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 Column DataMaps</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 #mainGrid [(itemsSource)]="data"> <wj-flex-grid-column [header]="'顧客'" [binding]="'customer'" width="1.5*" [dataMap]="customerMap"></wj-flex-grid-column> <wj-flex-grid-column [header]="'国'" [binding]="'country'" width="*" [dataMap]="countries"></wj-flex-grid-column> <wj-flex-grid-column [header]="'DL数'" [binding]="'downloads'" width="*" format="n0"></wj-flex-grid-column> <wj-flex-grid-column [header]="'売上'" [binding]="'sales'" width="*" format="n0"></wj-flex-grid-column> <wj-flex-grid-column [header]="'費用'" [binding]="'expenses'" width="*" format="n0"></wj-flex-grid-column> </wj-flex-grid> <p> 下記は顧客一覧のグリッドです。名前を編集すると、上のグリッドに変更が反映されます。</p> <wj-flex-grid #dataMapGrid [(itemsSource)]="customers" (initialized)="dataMapGridInitialized(dataMapGrid)"> <wj-flex-grid-column binding="id" header="ID" [width]="80"></wj-flex-grid-column> <wj-flex-grid-column binding="name" header="名前"></wj-flex-grid-column> <wj-flex-grid-column binding="address" header="住所" width="*"></wj-flex-grid-column> </wj-flex-grid> </div> .wj-flexgrid { max-height: 200px; margin: 12px 0; } import 'bootstrap.css'; import '@grapecity/wijmo.styles/wijmo.css'; import './app.css'; // import * as React from 'react'; import * as ReactDOM from 'react-dom'; import * as wjcGrid from '@grapecity/wijmo.grid'; import * as wjGrid from '@grapecity/wijmo.react.grid'; class App extends React.Component { constructor(props) { super(props); this.state = { data: null, customerMap: null, countries: 'アメリカ,ドイツ,イギリス,日本,スウェーデン,ノルウェー,デンマーク'.split(','), customers: [ { id: 0, name: '成宮 真紀', address: '愛知県春日井市味美白山町 1-9-X' }, { id: 1, name: '山本 雅治', address: '福岡県粕屋郡志免町御手洗 51-X' }, { id: 2, name: '加藤 泰江', address: '茨城県牛久市下根町 1504-XX' }, { id: 3, name: '川村 匡', address: '広島県広島市西区観音新町 1-16-X' }, ] }; } render() { return <div className="container-fluid"> <wjGrid.FlexGrid initialized={this.mainGridInitialized.bind(this)} itemsSource={this.state.data}> <wjGrid.FlexGridColumn header="顧客" binding="customer" width="1.5*" dataMap={this.state.customerMap}> </wjGrid.FlexGridColumn> <wjGrid.FlexGridColumn header="国" binding="country" width="*" dataMap={this.state.countries}> </wjGrid.FlexGridColumn> <wjGrid.FlexGridColumn header="DL数" binding="downloads" width="*" format="n0"> </wjGrid.FlexGridColumn> <wjGrid.FlexGridColumn header="売上" binding="sales" width="*" format="n0"> </wjGrid.FlexGridColumn> <wjGrid.FlexGridColumn header="費用" binding="expenses" width="*" format="n0"> </wjGrid.FlexGridColumn> </wjGrid.FlexGrid> <p> 下記は顧客一覧のグリッドです。名前を編集すると、上のグリッドに変更が反映されます。 </p> <wjGrid.FlexGrid initialized={this.dataMapGridInitialized.bind(this)} itemsSource={this.state.customers}> <wjGrid.FlexGridColumn binding="id" header="ID" width={80}></wjGrid.FlexGridColumn> <wjGrid.FlexGridColumn binding="name" header="名前"></wjGrid.FlexGridColumn> <wjGrid.FlexGridColumn binding="address" header="住所" width="*"></wjGrid.FlexGridColumn> </wjGrid.FlexGrid> </div>; } mainGridInitialized(mainGrid) { this.mainGrid = mainGrid; } dataMapGridInitialized(flexGrid) { var data = this.getData(); var customerMap = new wjcGrid.DataMap(this.state.customers, 'id', 'name'); var _this = this; flexGrid.rowEditEnded.addHandler(() => { let column = this.mainGrid.getColumn('customer'); if (column) { column.dataMap = new wjcGrid.DataMap(_this.state.customers, 'id', 'name'); } this.mainGrid.refresh(); // update customer names on the main grid }); this.setState({ data: data, customerMap: customerMap }); } getData() { let data = []; for (let i = 0; i < this.state.countries.length; i++) { data.push({ id: i, country: this.state.countries[i], customer: this.state.customers[i % this.state.customers.length].id, active: i % 5 != 0, downloads: Math.round(Math.random() * 200000), sales: Math.random() * 100000, expenses: Math.random() * 50000 }); } return data; } } 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 FlexGrid Column DataMaps</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: 200px; margin: 12px 0; } <template> <div class="container-fluid"> <wj-flex-grid :itemsSource="data" :initialized="mainGridInitialized"> <wj-flex-grid-column header="顧客" binding="customer" width="1.5*" :dataMap="customerMap"></wj-flex-grid-column> <wj-flex-grid-column header="国" binding="country" width="*" :dataMap="countries"></wj-flex-grid-column> <wj-flex-grid-column header="DL数" binding="downloads" width="*" format="n0"></wj-flex-grid-column> <wj-flex-grid-column header="売上" binding="sales" width="*" format="n0"></wj-flex-grid-column> <wj-flex-grid-column header="費用" binding="expenses" width="*" format="n0"></wj-flex-grid-column> </wj-flex-grid> <p> 下記は顧客一覧のグリッドです。名前を編集すると、上のグリッドに変更が反映されます。</p> <wj-flex-grid :itemsSource="customers" :initialized="dataMapGridInitialized"> <wj-flex-grid-column binding="id" header="ID" :width=80></wj-flex-grid-column> <wj-flex-grid-column binding="name" header="名前"></wj-flex-grid-column> <wj-flex-grid-column binding="address" header="住所" width="*"></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 * as wjcGrid from "@grapecity/wijmo.grid"; new Vue({ el: "#app", data: function() { return { countries: 'アメリカ,ドイツ,イギリス,日本,スウェーデン,ノルウェー,デンマーク'.split(','), customers: [ { id: 0, name: '成宮 真紀', address: '愛知県春日井市味美白山町 1-9-X' }, { id: 1, name: '山本 雅治', address: '福岡県粕屋郡志免町御手洗 51-X' }, { id: 2, name: '加藤 泰江', address: '茨城県牛久市下根町 1504-XX' }, { id: 3, name: '川村 匡', address: '広島県広島市西区観音新町 1-16-X' }, ], data: null, customerMap: null }; }, methods:{ mainGridInitialized(mainGrid){ this.mainGrid = mainGrid; }, dataMapGridInitialized(flexgrid) { this.data = this._getData(); this.customerMap = new wjcGrid.DataMap(this.customers, 'id', 'name'); var _this = this; flexgrid.rowEditEnded.addHandler(() => { let column = this.mainGrid.getColumn('customer'); if (column) { column.dataMap = new wjcGrid.DataMap(_this.customers, 'id', 'name'); } this.mainGrid.refresh(); // update customer names on the main grid }); }, _getData() { let data = []; for (let i = 0; i < this.countries.length; i++) { data.push({ id: i, country: this.countries[i], customer: this.customers[i % this.customers.length].id, active: i % 5 != 0, downloads: Math.round(Math.random() * 200000), sales: Math.random() * 100000, expenses: Math.random() * 50000 }); } return data; } } }); </script> <style> .wj-flexgrid { max-height: 200px; margin: 12px 0; } </style> <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <title>AutoComplete</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>