グリッド:選択

デフォルトでは、FlexGridを使用すると、Excelのようにマウスやキーボードでセルの範囲を選択できます。selectionModeプロパティでは、行、行範囲、連続しない行リスト、セル、セル範囲、選択なしのいずれかにユーザーの選択を制限することができます。

import 'bootstrap.css'; import '@grapecity/wijmo.styles/wijmo.css'; import './styles.css'; import * as wjGrid from '@grapecity/wijmo.grid'; import * as wjCore from '@grapecity/wijmo'; import * as wjInput from '@grapecity/wijmo.input'; // document.readyState === 'complete' ? init() : window.onload = init; // function init() { // // create some random data var countries = 'アメリカ,ドイツ,イギリス,日本,イタリア,ギリシャ'.split(','), data = []; for (var i = 0; i < countries.length; i++) { data.push({ country: countries[i], downloads: Math.round(Math.random() * 20000), sales: Math.random() * 10000, expenses: Math.random() * 5000 }); } // // show data in a grid var currSel = document.getElementById('currSel'); var theGrid = new wjGrid.FlexGrid('#theGrid', { autoGenerateColumns: false, columns: [ { binding: 'country', header: '国' }, { binding: 'downloads', header: 'DL数', width: 80 }, { binding: 'sales', header: '売上', width: 80 }, { binding: 'expenses', header: '費用', width: 80 }, ], alternatingRowStep: 0, itemsSource: data, selectionChanged: function (s, e) { currSel.textContent = wjCore.format('({row},{col})-({row2},{col2})', theGrid.selection); } }); theGrid.onSelectionChanged(null); // initialize selection display // // pick selectionMode var selectionMode = new wjInput.ComboBox('#selectionMode', { itemsSource: 'なし,セル,セル範囲,行,行範囲,行リスト'.split(','), text: 'セル範囲', textChanged: function () { theGrid.selectionMode = wjCore.asEnum(selectionMode.selectedIndex, wjGrid.SelectionMode); } }); // // select first four cells in the grid document.getElementById('btnSelect').addEventListener('click', function () { selectionMode.text = 'CellRange'; theGrid.selection = new wjGrid.CellRange(0, 0, 1, 1); }); // // select rows 0, 2, and 4 document.getElementById('btnListSelect').addEventListener('click', function () { selectionMode.text = '行リスト'; theGrid.select(0, 0); // regular selection still works in listbox mode [0, 2, 4].forEach(function (index) { theGrid.rows[index].isSelected = true; }); }); // } <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <title>GrapeCity Wijmo FlexGrid Seletion 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 class="container-fluid"> <label> 選択モード <div id="selectionMode"></div> </label> <div id="theGrid"></div> <p> 現在の選択範囲: <span id="currSel"></span>. </p> <div> <button id="btnSelect" class="btn btn-default"> 最初の4つのセルを選択 </button> <button id="btnListSelect" class="btn btn-default"> 0、2、4の行を選択 </button> </div> </div> </body> </html> .wj-flexgrid { max-height: 250px; margin:6px 0; } #currSel { font-weight: bold } body { margin-bottom: 12px; } import 'bootstrap.css'; import '@grapecity/wijmo.styles/wijmo.css'; import './styles.css'; import { Component, enableProdMode, NgModule, Inject, ViewChild } from '@angular/core'; import { FormsModule } from '@angular/forms'; import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; import { BrowserModule } from '@angular/platform-browser'; import { WjGridModule } from '@grapecity/wijmo.angular2.grid'; import { WjInputModule } from '@grapecity/wijmo.angular2.input'; import * as wjCore from '@grapecity/wijmo'; import * as wjInput from '@grapecity/wijmo.input'; import * as wjGrid from '@grapecity/wijmo.grid'; import { DataService, DataItem } from './app.data'; @Component({ selector: 'app-component', templateUrl: 'src/app.component.html' }) export class AppComponent { @ViewChild('flexGrid') flexGrid: wjGrid.FlexGrid; @ViewChild('selectionMode') selectionMode: wjInput.ComboBox; data: DataItem[]; comboBoxData: string[]; currentSelection: string; // DataSvc will be passed by derived classes constructor(@Inject(DataService) dataSvc: DataService) { this.data = dataSvc.getData(); this.comboBoxData = 'なし,セル,セル範囲,行,行範囲,行リスト'.split(','); } // initializeGrid() { this.flexGrid.onSelectionChanged(null); } // onTextChanged() { this.flexGrid.selectionMode = wjCore.asEnum(this.selectionMode.selectedIndex, wjGrid.SelectionMode); } // onSelectionChanged() { this.currentSelection = wjCore.format( '({row},{col})-({row2},{col2})', this.flexGrid.selection); } // onRefreshClick() { this.flexGrid.collectionView.refresh(); } // onSelectClick() { this.selectionMode.text = 'セル範囲'; this.flexGrid.selection = new wjGrid.CellRange(0, 0, 1, 1); } // onListSelectClick() { this.selectionMode.text = '行リスト'; this.flexGrid.select(0, 0); setTimeout(() => { [0, 2, 4].forEach((index) => { this.flexGrid.rows[index].isSelected = true; }); }); } } @NgModule({ imports: [WjGridModule, FormsModule, WjInputModule, BrowserModule], providers: [DataService], 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 Seletion Overview</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> 選択モード <span id="selectionMode"></span> <wj-combo-box #selectionMode [itemsSource]="comboBoxData" [text]="'セル範囲'" (textChanged)="onTextChanged()"></wj-combo-box> </label> <wj-flex-grid #flexGrid [alternatingRowStep]="0" [itemsSource]="data" (initialized)="initializeGrid(flex)" (selectionChanged)="onSelectionChanged()"> <wj-flex-grid-column binding="country" header="国"></wj-flex-grid-column> <wj-flex-grid-column binding="downloads" header="DL数" [width]="80"></wj-flex-grid-column> <wj-flex-grid-column binding="sales" header="売上" [width]="80"></wj-flex-grid-column> <wj-flex-grid-column binding="expenses" header="費用" [width]="80"></wj-flex-grid-column> </wj-flex-grid> <p> 現在の選択範囲: <span id="currSel">{{currentSelection}}</span>. </p> <div> <button class="btn btn-default" (click)="onSelectClick()"> 最初の4つのセルを選択 </button> <button class="btn btn-default" (click)="onListSelectClick()"> 0、2、4の行を選択 </button> </div> </div> import { Injectable } from '@angular/core'; export interface DataItem { country: string; downloads: number; sales: number; expenses: number; } @Injectable() export class DataService { getData(): DataItem[] { var countries = 'アメリカ,ドイツ,イギリス,日本,イタリア,ギリシャ'.split(','), data = []; for (var i = 0; i < countries.length; i++) { data.push({ country: countries[i], downloads: Math.round(Math.random() * 20000), sales: Math.random() * 10000, expenses: Math.random() * 5000 }); } return data; } } .wj-flexgrid { max-height: 250px; margin:6px 0; } #currSel { font-weight: bold } body { margin-bottom: 12px; } 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 wjcCore from "@grapecity/wijmo"; import * as wjcGrid from "@grapecity/wijmo.react.grid"; import * as wjGrid from "@grapecity/wijmo.grid"; import * as wjcInput from "@grapecity/wijmo.react.input"; import { getData } from "./data"; class App extends React.Component { constructor(props) { super(props); this.state = { data: getData(), comboBoxData: "なし,セル,セル範囲,行,行範囲,行リスト".split(","), currentSelection: null, currentComboText: "セル範囲" }; } render() { return <div className="container-fluid"> <label>選択モード{' '}<span id="selectionMode"></span> <wjcInput.ComboBox initialized={this.initCombo.bind(this)} itemsSource={this.state.comboBoxData} text={this.state.currentComboText} textChanged={this.onTextChanged.bind(this)}> </wjcInput.ComboBox> </label> <wjcGrid.FlexGrid alternatingRowStep={0} itemsSource={this.state.data} initialized={this.initializeGrid.bind(this)} selectionChanged={this.onSelectionChanged.bind(this)}> <wjcGrid.FlexGridColumn binding="country" header="国"></wjcGrid.FlexGridColumn> <wjcGrid.FlexGridColumn binding="downloads" header="DL数" width={80}></wjcGrid.FlexGridColumn> <wjcGrid.FlexGridColumn binding="sales" header="売上" width={80}></wjcGrid.FlexGridColumn> <wjcGrid.FlexGridColumn binding="expenses" header="費用" width={80}></wjcGrid.FlexGridColumn> </wjcGrid.FlexGrid> <p> 現在の選択範囲: <span id="currSel">{this.state.currentSelection}</span>. </p> <div> <button className="btn btn-default" onClick={this.onSelectClick.bind(this)}>最初の4つのセルを選択</button> <button className="btn btn-default" onClick={this.onListSelectClick.bind(this)}>0、2、4の行を選択</button> </div> </div>; } initCombo(combo) { this.combo = combo; } initializeGrid(flexGrid) { this.flexGrid = flexGrid; this.flexGrid.onSelectionChanged(null); } onTextChanged() { console.log("before============" + this.combo.selectedIndex); this.flexGrid.selectionMode = wjcCore.asEnum(this.combo.selectedIndex, wjGrid.SelectionMode); this.setState({ currentComboText: wjcCore.asEnum(this.combo.selectedIndex, wjGrid.SelectionMode) }); } onSelectionChanged() { this.setState({ currentSelection: wjcCore.format("({row},{col})-({row2},{col2})", this.flexGrid.selection) }); } onRefreshClick() { this.flexGrid.collectionView.refresh(); } onSelectClick() { this.combo.text = "セル範囲"; this.flexGrid.selection = new wjGrid.CellRange(0, 0, 1, 1); } onListSelectClick() { this.combo.text = "行リスト"; this.flexGrid.select(0, 0); [0, 2, 4].forEach((index) => { this.flexGrid.rows[index].isSelected = true; }); } } 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: 250px; margin: 10px; } #currSel { font-weight: bold; } body { margin-bottom: 12px; } export function getData() { var countries = 'アメリカ,ドイツ,イギリス,日本,イタリア,ギリシャ'.split(','), data = []; for (var i = 0; i < countries.length; i++) { data.push({ country: countries[i], downloads: Math.round(Math.random() * 20000), sales: Math.random() * 10000, expenses: Math.random() * 5000 }); } return data; } <template> <div class="container-fluid"> <label>選択モード <span id="selectionMode"></span> <wj-combo-box :initialized="initCombo" :itemsSource="comboBoxData" :text="'セル範囲'" :textChanged="onTextChanged" ></wj-combo-box> </label> <wj-flex-grid :alternatingRowStep="0" :itemsSource="data" :initialized="initializeGrid" :selectionChanged="onSelectionChanged"> <wj-flex-grid-column binding="country" header="国"></wj-flex-grid-column> <wj-flex-grid-column binding="downloads" header="DL数" :width=80></wj-flex-grid-column> <wj-flex-grid-column binding="sales" header="売上" :width=80></wj-flex-grid-column> <wj-flex-grid-column binding="expenses" header="費用" :width=80></wj-flex-grid-column> </wj-flex-grid> <p> 現在の選択範囲: <span id="currSel">{{currentSelection}}</span>. </p> <div> <button class="btn btn-default" @click="onSelectClick">最初の4つのセルを選択</button> <button class="btn btn-default" @click="onListSelectClick">0、2、4の行を選択</button> </div> </div> </template> <script> import "@grapecity/wijmo.styles/wijmo.css"; import "bootstrap.css"; import Vue from "vue"; import "@grapecity/wijmo.vue2.core"; import "@grapecity/wijmo.vue2.grid"; import "@grapecity/wijmo.vue2.input"; import * as wjGrid from "@grapecity/wijmo.grid"; import { getData } from "./data"; let App = Vue.extend({ name: "app", data: function() { return { data: getData(), comboBoxData: "なし,セル,セル範囲,行,行範囲,行リスト".split(","), currentSelection: null, flexGrid: null, selectionMode: null }; }, methods: { initCombo: function(combo) { this.selectionMode = combo; }, initializeGrid: function(flexGrid) { this.flexGrid = flexGrid; this.flexGrid.onSelectionChanged(null); }, onTextChanged: function() { this.flexGrid.selectionMode = wijmo.asEnum( this.selectionMode.selectedIndex, wjGrid.SelectionMode ); }, onSelectionChanged: function() { this.currentSelection = wijmo.format( "({row},{col})-({row2},{col2})", this.flexGrid.selection ); }, onRefreshClick: function() { this.flexGrid.collectionView.refresh(); }, onSelectClick: function() { this.selectionMode.text = "セル範囲"; this.flexGrid.selection = new wjGrid.CellRange(0, 0, 1, 1); }, onListSelectClick: function() { this.selectionMode.text = "行リスト"; this.flexGrid.select(0, 0); [0, 2, 4].forEach((index) => { this.flexGrid.rows[index].isSelected = true; }); } } }); new Vue({ render: h => h(App) }).$mount("#app"); </script> <style> .wj-flexgrid { max-height: 250px; margin: 10px; } #currSel { font-weight: bold; } body { margin-bottom: 12px; } </style> <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <title>GrapeCity Wijmo FlexGrid Seletion Overview</title> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <!-- SystemJS --> <script src="node_modules/jszip/dist/jszip.js"></script> <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 getData() { var countries = 'アメリカ,ドイツ,イギリス,日本,イタリア,ギリシャ'.split(','), data = []; for (var i = 0; i < countries.length; i++) { data.push({ country: countries[i], downloads: Math.round(Math.random() * 20000), sales: Math.random() * 10000, expenses: Math.random() * 5000 }); } return data; }