弹出框

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', { 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"> Save Layout </button> <button id="btnRestore" class="btn btn-default"> Restore Layout </button> </div> </body> </html> export function getData() { // create some random data let data = [], countries = ['US', 'Germany', 'UK', 'Japan', 'Italy', 'Greece'], products = ['Widget', 'Sprocket', 'Gadget', 'Doohickey'], colors = ['Black', 'White', 'Red', 'Green', 'Blue'], 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 } 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 { data: any; // constructor(@Inject(DataService) private dataService: DataService) { this.data = dataService.getData(); } // showPicker(picker: input.ListBox, ref: Element, e: MouseEvent) { 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, pickerIcon, $event)"></span> </ng-template> </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)"> Save Layout </button> <button class="btn btn-default" (click)="restoreLayout(theGrid)"> Restore Layout </button> </div> import { Injectable } from '@angular/core'; // @Injectable() export class DataService { getData() { // create some random data let data = [], countries = ['US', 'Germany', 'UK', 'Japan', 'Italy', 'Greece'], products = ['Widget', 'Sprocket', 'Gadget', 'Doohickey'], colors = ['Black', 'White', 'Red', 'Green', 'Blue'], 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; } <template> <div class="container-fluid"> <wj-flex-grid ref="theGrid" :itemsSource="data" :initialized="initializedFlexGrid" :formatItem='formatItem'> </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">Save Layout</button> <button class="btn btn-default" @click="restoreLayout">Restore Layout</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) { wijmo.showPopup( this.listbox.hostElement, e.target, 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 = ['US', 'Germany', 'UK', 'Japan', 'Italy', 'Greece'], products = ['Widget', 'Sprocket', 'Gadget', 'Doohickey'], colors = ['Black', 'White', 'Red', 'Green', 'Blue'], 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; } 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) => { wijmo.showPopup(this.state.listbox.hostElement, e.target, 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.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}>Save Layout</button> <button className="btn btn-default" onClick={this.restoreLayout}>Restore Layout</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 = ['US', 'Germany', 'UK', 'Japan', 'Italy', 'Greece'], products = ['Widget', 'Sprocket', 'Gadget', 'Doohickey'], colors = ['Black', 'White', 'Red', 'Green', 'Blue'], 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; }