列ピッカー

グリッドのcolumnsプロパティ、ListBoxコントロール、WijmoのshowPopupおよびhidePopupメソッドを使用して、列ピッカーUIを簡単に実装できます。たとえば、下のグリッドは自動生成された列のセットで始まります。左上のセルにある歯車のアイコンをクリックしてListBoxを表示し、そこで表示したい列を選択することができます。

import 'bootstrap.css'; import '@grapecity/wijmo.styles/wijmo.css'; import './styles.css'; import { showPopup, hidePopup, hasClass } from '@grapecity/wijmo'; import { ListBox } from '@grapecity/wijmo.input'; import { FlexGrid } from '@grapecity/wijmo.grid'; document.readyState === 'complete' ? init() : window.onload = init; function init() { // generate some random data var data = [], countries = ['アメリカ', 'ドイツ', 'イギリス', '日本', 'イタリア', 'ギリシャ'], products = ['ウィジェット', 'スプロケット', 'ガジェット', 'ツール'], colors = ['黒', '白', '赤', '緑', '青'], dt = new Date(); for (var i = 0; i < 100; i++) { var date = new Date(dt.getFullYear(), i % 12, 25, i % 24, i % 60, i % 60), countryId = Math.floor(Math.random() * countries.length), productId = Math.floor(Math.random() * products.length), colorId = Math.floor(Math.random() * colors.length); var item = { id: i, start: date, end: date, country: countries[countryId], product: products[productId], color: colors[colorId], countryId: countryId, productId: productId, colorId: colorId, amount1: Math.random() * 10000 - 5000, amount2: Math.random() * 10000 - 5000, amount3: Math.random() * 10000 - 5000, amount4: Math.random() * 10000 - 5000, amount5: Math.random() * 10000 - 5000, discount: Math.random() / 4, active: i % 4 == 0 }; data.push(item); } // create the grid var theGrid = new FlexGrid('#theGrid', { autoGenerateColumns: false, columns: [ { binding: 'id', header: 'ID', width: 80 }, { binding: 'start', header: '開始' }, { binding: 'end', header: '終了' }, { binding: 'country', header: '国' }, { binding: 'product', header: '商品' }, { binding: 'color', header: '色' }, { binding: 'countryId', header: '国ID', width: 80 }, { binding: 'productId', header: '商品ID', width: 80 }, { binding: 'colorId', header: '色ID', width: 80 }, { binding: 'amount1', header: '金額1', width: 80 }, { binding: 'amount2', header: '金額2', width: 80 }, { binding: 'amount3', header: '金額3', width: 80 }, { binding: 'amount4', header: '金額4', width: 80 }, { binding: 'amount5', header: '金額5', width: 80 }, { binding: 'discount', header: '値引', width: 80 }, { binding: 'active', header: '有効' }, ], itemsSource: data, formatItem: function (s, e) { if (e.panel == s.topLeftCells) { e.cell.innerHTML = '<span class="column-picker-icon glyphicon glyphicon-cog"></span>'; } } }); // create the column picker var theColumnPicker = new ListBox('#theColumnPicker', { itemsSource: theGrid.columns, checkedMemberPath: 'visible', displayMemberPath: 'header', lostFocus: function () { hidePopup(theColumnPicker.hostElement); } }); // show the column picker when the user clicks the top-left cell var ref = theGrid.hostElement.querySelector('.wj-topleft'); ref.addEventListener('mousedown', function (e) { if (hasClass(e.target, 'column-picker-icon')) { showPopup(theColumnPicker.hostElement, ref, false, true, false); theColumnPicker.focus(); e.preventDefault(); } }); // save/restore layout buttons document.getElementById('btnSave').addEventListener('click', function () { localStorage.setItem('myLayout', theGrid.columnLayout); }); document.getElementById('btnRestore').addEventListener('click', function () { var layout = localStorage.getItem('myLayout'); if (layout) { theGrid.columnLayout = layout; } }); } <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <title>GrapeCity Wijmo FlexGrid Column Picker</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> <div style="display:none"> <div id="theColumnPicker" class="column-picker"></div> </div> <p> グリッドの<b>columnLayout</b>プロパティを使用して、ユーザーが列レイアウトを保存および復元できるようにすることができます。以下のボタンをクリックして、この動作を確認してください。</p> <button id="btnSave" class="btn btn-default"> レイアウトを保存 </button> <button id="btnRestore" class="btn btn-default"> レイアウトを復元 </button> </div> </body> </html> .wj-flexgrid { max-height: 300px; margin: 10px 0; } .column-picker { columns: 3; padding: 12px; margin-left: 12px; margin-top: 26px; box-shadow: 0 10px 20px rgba(0,0,0,0.19), 0 6px 6px rgba(0,0,0,0.23); } .column-picker-icon { cursor: pointer; color: #FF8754; margin: 3px; } body { margin-bottom: 20px; } 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 wjcCore from '@grapecity/wijmo'; import * as wjcInput from '@grapecity/wijmo.input'; import * as wjcGrid from '@grapecity/wijmo.grid'; import { WjInputModule } from '@grapecity/wijmo.angular2.input'; import { WjGridModule } from '@grapecity/wijmo.angular2.grid'; // @Component({ selector: 'app-component', templateUrl: 'src/app.component.html' }) export class AppComponent { data: any[]; // references FlexGrid named 'flex' in the view @ViewChild('flex') flex: wjcGrid.FlexGrid; @ViewChild('columnPicker') columnPicker: wjcInput.ListBox; // DataSvc will be passed by derived classes constructor() { this.data = this._getData(); } ngOnInit() { if (this.flex) { this.flex.formatItem.addHandler((s: wjcGrid.FlexGrid, e: wjcGrid.FormatItemEventArgs) => { if (e.panel == s.topLeftCells) { e.cell.innerHTML = '<span class="column-picker-icon glyphicon glyphicon-cog"></span>'; } }); // show the column picker when the user clicks the top-left cell let ref = this.flex.hostElement.querySelector('.wj-topleft'); ref.addEventListener('mousedown', (e) => { if (wjcCore.hasClass(<Element>e.target, 'column-picker-icon')) { wjcCore.showPopup(this.columnPicker.hostElement, ref, false, true, false); this.columnPicker.focus(); e.preventDefault(); } }); } } ngAfterViewInit() { if (this.flex) { this.columnPicker.itemsSource = this.flex.columns; this.columnPicker.checkedMemberPath = 'visible'; this.columnPicker.displayMemberPath = 'header'; this.columnPicker.lostFocus.addHandler(() => { wjcCore.hidePopup(this.columnPicker.hostElement); }); } } saveLayout() { localStorage.setItem('myLayout', this.flex.columnLayout); } loadLayout() { let layout = localStorage.getItem('myLayout'); if (layout) { this.flex.columnLayout = layout; } } private _getData() { // generate some random data let data = [], countries = ['アメリカ', 'ドイツ', 'イギリス', '日本', 'イタリア', 'ギリシャ'], products = ['ウィジェット', 'スプロケット', 'ガジェット', 'ツール'], colors = ['黒', '白', '赤', '緑', '青'], dt = new Date(); for (let i = 0; i < 100; i++) { let date = new Date(dt.getFullYear(), i % 12, 25, i % 24, i % 60, i % 60), countryId = Math.floor(Math.random() * countries.length), productId = Math.floor(Math.random() * products.length), colorId = Math.floor(Math.random() * colors.length); let item = { id: i, start: date, end: date, country: countries[countryId], product: products[productId], color: colors[colorId], countryId: countryId, productId: productId, colorId: colorId, amount1: Math.random() * 10000 - 5000, amount2: Math.random() * 10000 - 5000, amount3: Math.random() * 10000 - 5000, amount4: Math.random() * 10000 - 5000, amount5: Math.random() * 10000 - 5000, discount: Math.random() / 4, active: i % 4 == 0 }; data.push(item); } 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 Picker</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 #flex [(itemsSource)]="data"> <wj-flex-grid-column binding="id" header="ID" [width]="80"></wj-flex-grid-column> <wj-flex-grid-column binding="start" header="開始"></wj-flex-grid-column> <wj-flex-grid-column binding="end" header="終了"></wj-flex-grid-column> <wj-flex-grid-column binding="country" header="国"></wj-flex-grid-column> <wj-flex-grid-column binding="product" header="商品"></wj-flex-grid-column> <wj-flex-grid-column binding="color" header="色"></wj-flex-grid-column> <wj-flex-grid-column binding="countryId" header="国ID"></wj-flex-grid-column> <wj-flex-grid-column binding="productId" header="商品ID"></wj-flex-grid-column> <wj-flex-grid-column binding="colorId" header="色ID"></wj-flex-grid-column> <wj-flex-grid-column binding="amount1" header="金額1" [width]="80"></wj-flex-grid-column> <wj-flex-grid-column binding="amount2" header="金額2" [width]="80"></wj-flex-grid-column> <wj-flex-grid-column binding="amount3" header="金額3" [width]="80"></wj-flex-grid-column> <wj-flex-grid-column binding="amount4" header="金額4" [width]="80"></wj-flex-grid-column> <wj-flex-grid-column binding="amount5" header="金額5" [width]="80"></wj-flex-grid-column> <wj-flex-grid-column binding="discount" header="値引" [width]="80"></wj-flex-grid-column> <wj-flex-grid-column binding="active" header="有効"></wj-flex-grid-column> </wj-flex-grid> <div style="display:none"> <wj-list-box #columnPicker class="column-picker"></wj-list-box> </div> <p> グリッドの<b>columnLayout</b>プロパティを使用して、ユーザーが列レイアウトを保存および復元できるようにすることができます。以下のボタンをクリックして、この動作を確認してください。</p> <button (click)="saveLayout()" class="btn btn-default">レイアウトを保存</button> <button (click)="loadLayout()" class="btn btn-default">レイアウトを復元</button> </div> .wj-flexgrid { max-height: 300px; margin: 10px 0; } .column-picker { columns: 3; padding: 12px; margin-left: 12px; margin-top: 26px; box-shadow: 0 10px 20px rgba(0,0,0,0.19), 0 6px 6px rgba(0,0,0,0.23); } .column-picker-icon { cursor: pointer; color: #FF8754; margin: 3px; } body { margin-bottom: 20px; } 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 * as wjcInput from '@grapecity/wijmo.react.input'; 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 initialized={this.initializedGrid.bind(this)} itemsSource={this.state.data}> <wjGrid.FlexGridColumn binding="id" header="ID" width={80}></wjGrid.FlexGridColumn> <wjGrid.FlexGridColumn binding="start" header="開始"></wjGrid.FlexGridColumn> <wjGrid.FlexGridColumn binding="end" header="終了"></wjGrid.FlexGridColumn> <wjGrid.FlexGridColumn binding="country" header="国"></wjGrid.FlexGridColumn> <wjGrid.FlexGridColumn binding="product" header="商品"></wjGrid.FlexGridColumn> <wjGrid.FlexGridColumn binding="color" header="色"></wjGrid.FlexGridColumn> <wjGrid.FlexGridColumn binding="countryId" header="国ID"></wjGrid.FlexGridColumn> <wjGrid.FlexGridColumn binding="productId" header="商品ID"></wjGrid.FlexGridColumn> <wjGrid.FlexGridColumn binding="colorId" header="色ID"></wjGrid.FlexGridColumn> <wjGrid.FlexGridColumn binding="amount1" header="金額1" width={80}></wjGrid.FlexGridColumn> <wjGrid.FlexGridColumn binding="amount2" header="金額2" width={80}></wjGrid.FlexGridColumn> <wjGrid.FlexGridColumn binding="amount3" header="金額3" width={80}></wjGrid.FlexGridColumn> <wjGrid.FlexGridColumn binding="amount4" header="金額4" width={80}></wjGrid.FlexGridColumn> <wjGrid.FlexGridColumn binding="amount5" header="金額5" width={80}></wjGrid.FlexGridColumn> <wjGrid.FlexGridColumn binding="discount" header="値引" width={80}></wjGrid.FlexGridColumn> <wjGrid.FlexGridColumn binding="active" header="有効"></wjGrid.FlexGridColumn> </wjGrid.FlexGrid> <div className="column-picker-div"> <wjcInput.ListBox className="column-picker" initialized={this.initializedPicker.bind(this)}> </wjcInput.ListBox> </div> <p> グリッドの<b>columnLayout</b>プロパティを使用して、ユーザーが列レイアウトを保存および復元できるようにすることができます。以下のボタンをクリックして、この動作を確認してください。 </p> <button className="btn btn-default" onClick={this.saveLayout.bind(this)}>レイアウトを保存</button> <button className="btn btn-default" onClick={this.loadLayout.bind(this)}>レイアウトを復元</button> </div>; } initializedGrid(ctl) { this.flex = ctl; this.flex.formatItem.addHandler((s, e) => { if (e.panel == s.topLeftCells) { e.cell.innerHTML = '<span class="column-picker-icon glyphicon glyphicon-cog"></span>'; } }); // show the column picker when the user clicks the top-left cell let ref = this.flex.hostElement.querySelector(".wj-topleft"); ref.addEventListener("mousedown", e => { if (wjcCore.hasClass(e.target, "column-picker-icon")) { wjcCore.showPopup(this.columnPicker.hostElement, ref, false, true, false); this.columnPicker.focus(); e.preventDefault(); } }); } initializedPicker(picker) { this.columnPicker = picker; } componentDidMount() { if (this.flex) { this.columnPicker.itemsSource = this.flex.columns; this.columnPicker.checkedMemberPath = 'visible'; this.columnPicker.displayMemberPath = 'header'; this.columnPicker.lostFocus.addHandler(() => { wjcCore.hidePopup(this.columnPicker.hostElement); }); } } saveLayout() { localStorage.setItem("myLayout", this.flex.columnLayout); } loadLayout() { let layout = localStorage.getItem("myLayout"); if (layout) { this.flex.columnLayout = layout; } } } 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 Picker</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: 300px; margin: 10px 0; } .column-picker { columns: 3; padding: 12px; margin-left: 12px; margin-top: 26px; box-shadow: 0 10px 20px rgba(0,0,0,0.19), 0 6px 6px rgba(0,0,0,0.23); } .column-picker-icon { cursor: pointer; color: #FF8754; margin: 3px; } .column-picker-div { display: none; } body { margin-bottom: 20px; } export function getData() { let data = [], countries = ['アメリカ', 'ドイツ', 'イギリス', '日本', 'イタリア', 'ギリシャ'], products = ['ウィジェット', 'スプロケット', 'ガジェット', 'ツール'], colors = ['黒', '白', '赤', '緑', '青'], dt = new Date(); for (let i = 0; i < 100; i++) { let date = new Date(dt.getFullYear(), i % 12, 25, i % 24, i % 60, i % 60), countryId = Math.floor(Math.random() * countries.length), productId = Math.floor(Math.random() * products.length), colorId = Math.floor(Math.random() * colors.length); let item = { id: i, start: date, end: date, country: countries[countryId], product: products[productId], color: colors[colorId], countryId: countryId, productId: productId, colorId: colorId, amount1: Math.random() * 10000 - 5000, amount2: Math.random() * 10000 - 5000, amount3: Math.random() * 10000 - 5000, amount4: Math.random() * 10000 - 5000, amount5: Math.random() * 10000 - 5000, discount: Math.random() / 4, active: i % 4 == 0 }; data.push(item); } return data; } <template> <div class="container-fluid"> <wj-flex-grid :itemsSource="data" :initialized="initializedGrid"> <wj-flex-grid-column binding="id" header="ID" :width=80></wj-flex-grid-column> <wj-flex-grid-column binding="start" header="開始"></wj-flex-grid-column> <wj-flex-grid-column binding="end" header="終了"></wj-flex-grid-column> <wj-flex-grid-column binding="country" header="国"></wj-flex-grid-column> <wj-flex-grid-column binding="product" header="商品"></wj-flex-grid-column> <wj-flex-grid-column binding="color" header="色"></wj-flex-grid-column> <wj-flex-grid-column binding="countryId" header="国ID"></wj-flex-grid-column> <wj-flex-grid-column binding="productId" header="商品ID"></wj-flex-grid-column> <wj-flex-grid-column binding="colorId" header="色ID"></wj-flex-grid-column> <wj-flex-grid-column binding="amount1" header="金額1" :width=80></wj-flex-grid-column> <wj-flex-grid-column binding="amount2" header="金額2" :width=80></wj-flex-grid-column> <wj-flex-grid-column binding="amount3" header="金額3" :width=80></wj-flex-grid-column> <wj-flex-grid-column binding="amount4" header="金額4" :width=80></wj-flex-grid-column> <wj-flex-grid-column binding="amount5" header="金額5" :width=80></wj-flex-grid-column> <wj-flex-grid-column binding="discount" header="値引" :width=80></wj-flex-grid-column> <wj-flex-grid-column binding="active" header="有効"></wj-flex-grid-column> </wj-flex-grid> <div style="display:none"> <wj-list-box class="column-picker" :initialized="initializedPicker"></wj-list-box> </div> <p> グリッドの<b>columnLayout</b>プロパティを使用して、ユーザーが列レイアウトを保存および復元できるようにすることができます。以下のボタンをクリックして、この動作を確認してください。 </p> <button v-on:click="saveLayout" class="btn btn-default">レイアウトを保存</button> <button v-on:click="loadLayout" class="btn btn-default">レイアウトを復元</button> </div> </template> <script> import "@grapecity/wijmo.styles/wijmo.css"; import "bootstrap.css"; import Vue from "vue"; import "@grapecity/wijmo.vue2.grid"; import "@grapecity/wijmo.vue2.input"; import * as wjcCore from "@grapecity/wijmo"; import * as wjcInput from "@grapecity/wijmo.input"; import * as wjcGrid from "@grapecity/wijmo.grid"; import { getData } from "./data"; new Vue({ el: "#app", data: function() { return { data: getData() }; }, methods: { saveLayout() { localStorage.setItem("myLayout", this.flex.columnLayout); }, loadLayout() { let layout = localStorage.getItem("myLayout"); if (layout) { this.flex.columnLayout = layout; } }, initializedPicker(picker){ this.columnPicker = picker; }, initializedGrid(ctl) { this.flex = ctl; this.flex.formatItem.addHandler((s, e) => { if (e.panel == s.topLeftCells) { e.cell.innerHTML = '<span class="column-picker-icon glyphicon glyphicon-cog"></span>'; } }); // show the column picker when the user clicks the top-left cell let ref = this.flex.hostElement.querySelector(".wj-topleft"); ref.addEventListener("mousedown", e => { if (wjcCore.hasClass(e.target, "column-picker-icon")) { wjcCore.showPopup(this.columnPicker.hostElement, ref, false, true, false); this.columnPicker.focus(); e.preventDefault(); } }); } }, mounted: function(){ if (this.flex) { this.columnPicker.itemsSource = this.flex.columns; this.columnPicker.checkedMemberPath = 'visible'; this.columnPicker.displayMemberPath = 'header'; this.columnPicker.lostFocus.addHandler(() => { wjcCore.hidePopup(this.columnPicker.hostElement); }); } } }); </script> <style> .wj-flexgrid { max-height: 300px; margin: 10px 0; } .column-picker { columns: 3; padding: 12px; margin-left: 12px; margin-top: 26px; box-shadow: 0 10px 20px rgba(0,0,0,0.19), 0 6px 6px rgba(0,0,0,0.23); } .column-picker-icon { cursor: pointer; color: #FF8754; margin: 3px; } body { margin-bottom: 20px; } </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> export function getData() { let data = [], countries = ['アメリカ', 'ドイツ', 'イギリス', '日本', 'イタリア', 'ギリシャ'], products = ['ウィジェット', 'スプロケット', 'ガジェット', 'ツール'], colors = ['黒', '白', '赤', '緑', '青'], dt = new Date(); for (let i = 0; i < 100; i++) { let date = new Date(dt.getFullYear(), i % 12, 25, i % 24, i % 60, i % 60), countryId = Math.floor(Math.random() * countries.length), productId = Math.floor(Math.random() * products.length), colorId = Math.floor(Math.random() * colors.length); let item = { id: i, start: date, end: date, country: countries[countryId], product: products[productId], color: colors[colorId], countryId: countryId, productId: productId, colorId: colorId, amount1: Math.random() * 10000 - 5000, amount2: Math.random() * 10000 - 5000, amount3: Math.random() * 10000 - 5000, amount4: Math.random() * 10000 - 5000, amount5: Math.random() * 10000 - 5000, discount: Math.random() / 4, active: i % 4 == 0 }; data.push(item); } return data; }