ポップアップ

WijmoのshowPopupおよびhidePopupメソッドを使用すると、カスタムポップアップを作成できます。このサンプルでは、showPopup/hidePopupメソッドを使用してFlexGridコントロールの列ピッカーUIを表示します。左上のセルにある歯車のアイコンをクリックして、列ピッカーのUIを操作します。

import 'bootstrap.css'; import '@grapecity/wijmo.styles/wijmo.css'; import './styles.css'; // import * as wijmo from '@grapecity/wijmo'; import * as input from '@grapecity/wijmo.input'; import * as grid from '@grapecity/wijmo.grid'; // import { getData } from './data'; // document.readyState === 'complete' ? init() : window.onload = init; // function init() { // create the grid let theGrid = new grid.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: getData(), formatItem: (sender, e) => { if (e.panel == sender.topLeftCells) { e.cell.innerHTML = '<span class="column-picker-icon glyphicon glyphicon-cog"></span>'; } } }); // // create the column picker let theColumnPicker = new input.ListBox('#theColumnPicker', { itemsSource: theGrid.columns, checkedMemberPath: 'visible', displayMemberPath: 'header', lostFocus: () => wijmo.hidePopup(theColumnPicker.hostElement) }); // // show the column picker when the user clicks the top-left cell let ref = theGrid.hostElement.querySelector('.wj-topleft'); ref.addEventListener('mousedown', e => { if (wijmo.hasClass(e.target, 'column-picker-icon')) { wijmo.showPopup(theColumnPicker.hostElement, ref, false, true, false); theColumnPicker.focus(); e.preventDefault(); } }); // // save/restore layout buttons document.querySelector('#btnSave').addEventListener('click', () => { localStorage.setItem('myLayout', theGrid.columnLayout); }); // document.querySelector('#btnRestore').addEventListener('click', () => { let 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 Popup 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> <button id="btnSave" class="btn btn-default"> レイアウトを保存 </button> <button id="btnRestore" class="btn btn-default"> レイアウトを復元 </button> </div> </body> </html> export function getData() { // create 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); // data.push({ 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 }); } // return data; } .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); } /* #372131 (Chrome) */ .column-picker .wj-listbox-item { break-inside: avoid; } .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 * as wijmo from '@grapecity/wijmo'; import * as input from '@grapecity/wijmo.input'; import * as grid from '@grapecity/wijmo.grid'; // import { Component, Inject, enableProdMode, NgModule, ViewChild } from '@angular/core'; 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 { DataService } from './app.data'; // @Component({ selector: 'app-component', templateUrl: 'src/app.component.html' }) export class AppComponent { @ViewChild('theGrid') private _grid: grid.FlexGrid; data: any; // constructor(@Inject(DataService) private dataService: DataService) { this.data = dataService.getData(); } // showPicker(picker: input.ListBox, e: MouseEvent) { // show the column picker when the user clicks the top-left cell const ref = this._grid.hostElement.querySelector('.wj-topleft'); wijmo.showPopup(picker.hostElement, ref, false, true, false); picker.focus(); e.preventDefault(); } // hidePicker(picker: input.ListBox) { wijmo.hidePopup(picker.hostElement) } // saveLayout(flex: grid.FlexGrid) { localStorage.setItem('myLayout', flex.columnLayout); } // restoreLayout(flex: grid.FlexGrid) { let layout = localStorage.getItem('myLayout'); if (layout) { flex.columnLayout = layout; } } } // @NgModule({ imports: [WjGridModule, WjInputModule, 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 Popup 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 #theGrid [itemsSource]="data"> <ng-template wjFlexGridCellTemplate [cellType]="'TopLeft'"> <span #pickerIcon class="column-picker-icon glyphicon glyphicon-cog" (mousedown)="showPicker(picker, $event)"></span> </ng-template> <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 #picker class="column-picker" [itemsSource]="theGrid.columns" [checkedMemberPath]="'visible'" [displayMemberPath]="'header'" (lostFocus)="hidePicker(picker)"> </wj-list-box> </div> <button class="btn btn-default" (click)="saveLayout(theGrid)"> レイアウトを保存 </button> <button class="btn btn-default" (click)="restoreLayout(theGrid)"> レイアウトを復元 </button> </div> import { Injectable } from '@angular/core'; // @Injectable() export class DataService { getData() { // create 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); // data.push({ 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 }); } // return data; } } .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); } /* #372131 (Chrome) */ .column-picker .wj-listbox-item { break-inside: avoid; } .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 wijmo from '@grapecity/wijmo'; import * as wjGrid from '@grapecity/wijmo.react.grid'; import * as wjInput from '@grapecity/wijmo.react.input'; import { getData } from './data'; class App extends React.Component { constructor(props) { super(props); this.showPicker = (e) => { // show the column picker when the user clicks the top-left cell const ref = this.state.grid.hostElement.querySelector('.wj-topleft'); wijmo.showPopup(this.state.listbox.hostElement, ref, false, true, false); this.state.listbox.focus(); e.preventDefault(); }; this.hidePicker = () => { wijmo.hidePopup(this.state.listbox.hostElement); }; this.initializedFlexGrid = (grid) => { this.setState({ grid: grid, columns: grid.columns }); }; this.saveLayout = () => { localStorage.setItem("myLayout", this.state.grid.columnLayout); }; this.restoreLayout = () => { let layout = localStorage.getItem("myLayout"); if (layout) { this.state.grid.columnLayout = layout; } }; this.initializedListBox = (listbox) => { this.setState({ listbox: listbox }); }; this.formatItem = (sender, e) => { var self = this; if (e.panel == sender.topLeftCells) { var span = document.createElement("span"); span.className = "column-picker-icon glyphicon glyphicon-cog"; span.addEventListener('mousedown', function (e) { self.showPicker(e); }); e.cell.appendChild(span); } }; this.state = { data: getData(), columns: [], grid: {}, listbox: {} }; } render() { return <div className="container-fluid"> <wjGrid.FlexGrid ref="theGrid" initialized={this.initializedFlexGrid} formatItem={this.formatItem} 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 style={{ display: "none" }}> <wjInput.ListBox ref="picker" className="column-picker" itemsSource={this.state.columns} checkedMemberPath="visible" displayMemberPath="header" lostFocus={this.hidePicker} initialized={this.initializedListBox}></wjInput.ListBox> </div> <button className="btn btn-default" onClick={this.saveLayout}>レイアウトを保存</button> <button className="btn btn-default" onClick={this.restoreLayout}>レイアウトを復元</button> </div>; } } 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>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'); </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); } /* #372131 (Chrome) */ .column-picker .wj-listbox-item { break-inside: avoid; } .column-picker-icon { cursor: pointer; color: #FF8754; margin: 3px; } body { margin-bottom: 20px; } export function getData() { // create 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); // data.push({ 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 }); } // return data; } <template> <div class="container-fluid"> <wj-flex-grid ref="theGrid" :itemsSource="data" :initialized="initializedFlexGrid" :formatItem='formatItem'> <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 ref="picker" class="column-picker" :itemsSource="columns" :checkedMemberPath="'visible'" :displayMemberPath="'header'" :lostFocus="hidePicker" :initialized="initializedListBox" ></wj-list-box> </div> <button class="btn btn-default" @click="saveLayout">レイアウトを保存</button> <button class="btn btn-default" @click="restoreLayout">レイアウトを復元</button> </div> </template> <script> import "bootstrap.css"; import "@grapecity/wijmo.styles/wijmo.css"; import Vue from "vue"; import * as wijmo from "@grapecity/wijmo"; import * as grid from "@grapecity/wijmo.grid"; import "@grapecity/wijmo.vue2.input"; import "@grapecity/wijmo.vue2.grid"; import { getData } from "./data"; let App = Vue.extend({ name: "app", data: function() { return { data: getData(), columns: [] }; }, methods: { showPicker: function(e) { // show the column picker when the user clicks the top-left cell const ref = this.grid.hostElement.querySelector('.wj-topleft'); wijmo.showPopup( this.listbox.hostElement, ref, false, true, false ); this.listbox.focus(); e.preventDefault(); }, hidePicker: function() { wijmo.hidePopup(this.listbox.hostElement); }, saveLayout: function() { localStorage.setItem("myLayout", this.grid.columnLayout); }, restoreLayout: function() { let layout = localStorage.getItem("myLayout"); if (layout) { this.grid.columnLayout = layout; } }, initializedFlexGrid: function(grid) { this.grid = grid; this.columns = this.grid.columns; }, initializedListBox: function(listbox) { this.listbox = listbox; }, formatItem: function(sender, e) { var self = this; if (e.panel == sender.topLeftCells) { var span = document.createElement("span"); span.className = "column-picker-icon glyphicon glyphicon-cog"; span.addEventListener('mousedown',function(e){ self.showPicker(e); }); e.cell.appendChild(span); } } } }); new Vue({ render: h => h(App) }).$mount("#app"); </script> <style> .container-fluid .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; } /* #372131 (Chrome) */ .column-picker .wj-listbox-item { break-inside: avoid; } 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>GrapeCity Popup 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.vue'); </script> </head> <body> <div id="app"> </div> </body> </html> export function getData() { // create 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); // data.push({ 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 }); } // return data; }