グリッド:クリップボード

FlexGridはクリップボードをサポートしています。デフォルトでは、Ctrl+CまたはCtrl+Insertキーを押すと、現在の選択内容がクリップボードにコピーされます。Ctrl+VまたはShift+Insertキーを押すと、クリップボードの内容がグリッドに貼り付けられます。copyingcopiedpastingpastedpastingCellpastedCellの各イベントを使用して、クリップボードの動作をカスタマイズできます。FlexGridは、貼り付け時にクリップボードのデータを複製するExcelスタイルの「スマートペースト」機能を実装しています。たとえば、1つのセルを選択してCtrl+Cを押してクリップボードにコピーした後、選択範囲を広げてCtrl+Vを押すと、選択範囲全体にセルが貼り付けられます。

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'; // document.readyState === 'complete' ? init() : window.onload = init; // function init() { // // create some random data var countries = 'アメリカ,ドイツ,イギリス,日本,スウェーデン,ノルウェー,デンマーク'.split(','); var data = []; for (var i = 0; i < countries.length; i++) { data.push({ id: i, country: countries[i], active: i % 5 != 0, downloads: Math.round(Math.random() * 200000), sales: Math.random() * 100000, expenses: Math.random() * 50000 }); } // // default clipboard behavior var theGrid = new wjGrid.FlexGrid('#theGrid', { autoGenerateColumns: false, columns: [ { binding: 'id', header: 'ID', width: 80 }, { binding: 'country', header: '国' }, { binding: 'active', header: '有効' }, { binding: 'downloads', header: 'DL数', width: 80 }, { binding: 'sales', header: '売上', width: 80 }, { binding: 'expenses', header: '費用', width: 80 }, ], alternatingRowStep: 0, itemsSource: data, }); // // custom clipboard behavior var theCustomGrid = new wjGrid.FlexGrid('#theCustomGrid', { autoGenerateColumns: false, columns: [ { binding: 'id', header: 'ID', width: 80 }, { binding: 'country', header: '国' }, { binding: 'active', header: '有効' }, { binding: 'downloads', header: 'DL数', width: 80 }, { binding: 'sales', header: '売上', width: 80 }, { binding: 'expenses', header: '費用', width: 80 }, ], alternatingRowStep: 0, itemsSource: data, copying: function (s, e) { var text = s.getClipString(); var sel = s.selection; var hdr = ''; for (var c = sel.leftCol; c <= sel.rightCol; c++) { if (hdr) hdr += '\t'; hdr += s.columns[c].header; } text = hdr + '\r\n' + text; // // put text with headers on the clipboard wjCore.Clipboard.copy(text); // // prevent the grid from overwriting our clipboard content e.cancel = true; }, pasting: function (s, e) { e.cancel = true; // prevent pasting data with headers } }); } <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <title>GrapeCity Wijmo FlexGrid Clipboard</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> <h2>ヘッダを含めてコピー(貼り付け禁止)</h2> <div id="theCustomGrid"> </div> </div> </body> </html> .wj-flexgrid { max-height: 200px; margin-bottom: 12px; } body { margin-bottom: 24px; } import 'bootstrap.css'; import '@grapecity/wijmo.styles/wijmo.css'; import './styles.css'; import { Component, 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 * as wjcCore from '@grapecity/wijmo'; import * as wjcGrid from '@grapecity/wijmo.grid'; @Component({ selector: 'app-component', templateUrl: 'src/app.component.html' }) export class AppComponent { data: any[]; constructor() { this.data = this._getData(); } initializeCustomGrid(flex: wjcGrid.FlexGrid) { flex.copying.addHandler((s: wjcGrid.FlexGrid, e: wjcGrid.CellRangeEventArgs) => { // // add headers to clip string let text = s.getClipString(), sel = s.selection, hdr = ''; for (let c = sel.leftCol; c <= sel.rightCol; c++) { if (hdr) { hdr += '\t'; } hdr += s.columns[c].header; } text = hdr + '\r\n' + text; // put text with headers on the clipboard wjcCore.Clipboard.copy(text); // prevent the grid from overwriting our clipboard content e.cancel = true; }); flex.pasting.addHandler((s: wjcGrid.FlexGrid, e: wjcGrid.CellRangeEventArgs) => { e.cancel = true; // prevent pasting data with headers }); } private _getData() { // create some random data let countries = 'アメリカ,ドイツ,イギリス,日本,スウェーデン,ノルウェー,デンマーク'.split(','), data = []; for (let i = 0; i < countries.length; i++) { data.push({ id: i, country: countries[i], active: i % 5 != 0, downloads: Math.round(Math.random() * 200000), sales: Math.random() * 100000, expenses: Math.random() * 50000 }); } return data; } } @NgModule({ imports: [WjGridModule, 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 Clipboard</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"> <!-- the grid --> <wj-flex-grid #flex [alternatingRowStep]="0" [(itemsSource)]="data"> <wj-flex-grid-column binding="id" header="ID" [width]="80"></wj-flex-grid-column> <wj-flex-grid-column binding="country" header="国"></wj-flex-grid-column> <wj-flex-grid-column binding="active" 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> <h2>ヘッダを含めてコピー(貼り付け禁止)</h2> <wj-flex-grid #customFlex [alternatingRowStep]="0" [(itemsSource)]="data" (initialized)="initializeCustomGrid(customFlex)"> <wj-flex-grid-column binding="id" header="ID" [width]="80"></wj-flex-grid-column> <wj-flex-grid-column binding="country" header="国"></wj-flex-grid-column> <wj-flex-grid-column binding="active" 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> </div> .wj-flexgrid { max-height: 200px; margin-bottom: 12px; } body { margin-bottom: 24px; } 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 wjGrid from '@grapecity/wijmo.react.grid'; import * as wjcCore from '@grapecity/wijmo'; import { getData } from './data'; class App extends React.Component { constructor(props) { super(props); this.state = { data: getData() }; } render() { return <div className="container-fluid"> <wjGrid.FlexGrid alternatingRowStep={0} itemsSource={this.state.data}> <wjGrid.FlexGridColumn binding="id" header="ID" width={80}></wjGrid.FlexGridColumn> <wjGrid.FlexGridColumn binding="country" header="国"></wjGrid.FlexGridColumn> <wjGrid.FlexGridColumn binding="active" header="有効"></wjGrid.FlexGridColumn> <wjGrid.FlexGridColumn binding="downloads" header="DL数" width={80}></wjGrid.FlexGridColumn> <wjGrid.FlexGridColumn binding="sales" header="売上" width={80}></wjGrid.FlexGridColumn> <wjGrid.FlexGridColumn binding="expenses" header="費用" width={80}></wjGrid.FlexGridColumn> </wjGrid.FlexGrid> <h2>ヘッダを含めてコピー(貼り付け禁止)</h2> <wjGrid.FlexGrid alternatingRowStep={0} initialized={this.initializeCustomGrid.bind(this)} itemsSource={this.state.data}> <wjGrid.FlexGridColumn binding="id" header="ID" width={80}></wjGrid.FlexGridColumn> <wjGrid.FlexGridColumn binding="country" header="国"></wjGrid.FlexGridColumn> <wjGrid.FlexGridColumn binding="active" header="有効"></wjGrid.FlexGridColumn> <wjGrid.FlexGridColumn binding="downloads" header="DL数" width={80}></wjGrid.FlexGridColumn> <wjGrid.FlexGridColumn binding="sales" header="売上" width={80}></wjGrid.FlexGridColumn> <wjGrid.FlexGridColumn binding="expenses" header="費用" width={80}></wjGrid.FlexGridColumn> </wjGrid.FlexGrid> </div>; } initializeCustomGrid(flex) { flex.copying.addHandler((s, e) => { // // add headers to clip string let text = s.getClipString(), sel = s.selection, hdr = ""; for (let c = sel.leftCol; c <= sel.rightCol; c++) { if (hdr) { hdr += "\t"; } hdr += s.columns[c].header; } text = hdr + "\r\n" + text; // put text with headers on the clipboard wjcCore.Clipboard.copy(text); // prevent the grid from overwriting our clipboard content e.cancel = true; }); flex.pasting.addHandler((s, e) => { e.cancel = true; // prevent pasting data with headers }); } } 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 Clipboard</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-bottom: 12px; } body { margin-bottom: 24px; } export function getData() { // create some random data let countries = 'アメリカ,ドイツ,イギリス,日本,スウェーデン,ノルウェー,デンマーク'.split(','), data = []; for (let i = 0; i < countries.length; i++) { data.push({ id: i, country: countries[i], active: i % 5 != 0, downloads: Math.round(Math.random() * 200000), sales: Math.random() * 100000, expenses: Math.random() * 50000 }); } return data; } <template> <div class="container-fluid"> <!-- the grid --> <wj-flex-grid :alternatingRowStep="0" :itemsSource="data" > <wj-flex-grid-column binding="id" header="ID" :width=80></wj-flex-grid-column> <wj-flex-grid-column binding="country" header="国"></wj-flex-grid-column> <wj-flex-grid-column binding="active" 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> <h2>ヘッダを含めてコピー(貼り付け禁止)</h2> <wj-flex-grid :alternatingRowStep="0" :itemsSource="data" :initialized="initializeCustomGrid" > <wj-flex-grid-column binding="id" header="ID" :width=80></wj-flex-grid-column> <wj-flex-grid-column binding="country" header="国"></wj-flex-grid-column> <wj-flex-grid-column binding="active" 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> </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 { getData } from "./data"; let App = Vue.extend({ name: "app", data: function() { return { data: getData() }; }, methods: { initializeCustomGrid: function(flex) { flex.copying.addHandler((s, e) => { // // add headers to clip string let text = s.getClipString(), sel = s.selection, hdr = ""; for (let c = sel.leftCol; c <= sel.rightCol; c++) { if (hdr) { hdr += "\t"; } hdr += s.columns[c].header; } text = hdr + "\r\n" + text; // put text with headers on the clipboard wijmo.Clipboard.copy(text); // prevent the grid from overwriting our clipboard content e.cancel = true; }); flex.pasting.addHandler((s, e) => { e.cancel = true; // prevent pasting data with headers }); } } }); new Vue({ render: h => h(App) }).$mount("#app"); </script> <style> .wj-flexgrid { max-height: 200px; margin-bottom: 12px; } 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 Clipboard</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() { // create some random data let countries = 'アメリカ,ドイツ,イギリス,日本,スウェーデン,ノルウェー,デンマーク'.split(','), data = []; for (let i = 0; i < countries.length; i++) { data.push({ id: i, country: countries[i], active: i % 5 != 0, downloads: Math.round(Math.random() * 200000), sales: Math.random() * 100000, expenses: Math.random() * 50000 }); } return data; }