読み込み中表示

このサンプルでは、FlexGridコントロールにスピナーを追加して、データを読み込み中であることを示します。基本的な考え方は、データの読み込みを開始するときに、スピナー要素をグリッドに追加し、読み込みが完了したときにスピナーを削除することです。

import 'bootstrap.css'; import '@grapecity/wijmo.styles/wijmo.css'; import './styles.css'; import * as grid from '@grapecity/wijmo.grid'; import * as gauge from '@grapecity/wijmo.gauge'; import { getData } from './data'; import * as core from '@grapecity/wijmo'; // document.readyState === 'complete' ? init() : window.onload = init; // function init() { // create a grid to use with GIF spinner let theGridGif = new grid.FlexGrid('#theGridGif'); let theSpinnerGif = document.querySelector('#theSpinnerGif'); const gifWrapper = document.querySelector('#gifWrapper'); // // load data into the grid document.querySelector('#btn-load-gif').addEventListener('click', () => { // prepare to load data theGridGif.isDisabled = true; theGridGif.itemsSource = null; core.toggleClass(theGridGif.hostElement, 'hidden'); gifWrapper.appendChild(theSpinnerGif); // // load data with a delay getData((data) => { theGridGif.itemsSource = data; theGridGif.columns.forEach(column => { column.header = ['ID', '国', '売上', 'DL数'][column.index]; }); theGridGif.isDisabled = false; gifWrapper.removeChild(theSpinnerGif); core.toggleClass(theGridGif.hostElement, 'hidden'); }, 3000); }); // // create a grid to use with Gauge spinner let theGridGauge = new grid.FlexGrid('#theGridGauge'); const gaugeWrapper = document.querySelector('#gaugeWrapper'); // // load data into the grid document.querySelector('#btn-load-gauge').addEventListener('click', () => { // // prepare to load data core.toggleClass(theGridGauge.hostElement, 'hidden'); theGridGauge.itemsSource = null; setSpinner(theGridGauge, true); // // load data getData((data) => { theGridGauge.itemsSource = data; theGridGauge.columns.forEach(column => { column.header = ['ID', '国', '売上', 'DL数'][column.index]; }); setSpinner(theGridGauge, false); core.toggleClass(theGridGauge.hostElement, 'hidden'); }, 3000); }); // // create a spinner Gauge let theSpinnerInterval; let theSpinnerGauge = new gauge.RadialGauge('#theSpinnerGauge', { isAnimated: false, showText: 'None', sweepAngle: 360, step: 5, showTicks: true, face: { color: 'transparent' } }); // // add or remove a spinner to/from the grid function setSpinner(grid, on) { // stop spinner if (theSpinnerInterval) { clearInterval(theSpinnerInterval); theSpinnerInterval = null; } // // add/remove spinner let spinner = theSpinnerGauge.hostElement; if (on) { grid.isDisabled = true; gaugeWrapper.appendChild(spinner); theSpinnerGauge.invalidate(); theSpinnerGauge.value = 0; theSpinnerInterval = setInterval(() => { theSpinnerGauge.value = (theSpinnerGauge.value + 1) % 100; }, 50); } else { grid.isDisabled = false; gaugeWrapper.removeChild(spinner); } } } <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <title>GrapeCity FlexGrid Spinners</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"> <h3> GIFスピナー</h3> <p> この例では、グリッドの読み込み中にアニメーションGIFを表示します。</p> <button id="btn-load-gif" class="btn btn-primary"> GIFスピナーを使用してグリッドを読み込む </button> <div id="gifWrapper"> <div id="theGridGif"></div> <div style="display:none"> <div id="theSpinnerGif" class="spinner"> <img src="resources/Rounded%20blocks.gif"> </div> </div> </div> <h3> ゲージスピナー </h3> <p> この例では、グリッドの読み込み中にアニメーションRadialGaugeを表示します。</p> <button id="btn-load-gauge" class="btn btn-primary"> ゲージスピナーを使用してグリッドを読み込む </button> <div id="gaugeWrapper"> <div id="theGridGauge"></div> <div style="display:none"> <div id="theSpinnerGauge" class="spinner"></div> </div> </div> </div> </body> </html> // get some data asynchronously export function getData(callback, delay) { let countries = ['アメリカ', 'イギリス', '中国', 'ドイツ', 'インド'], data = []; // for (let i = 0; i < 1000; i++) { data.push({ id: i, country: countries[i % countries.length], sales: Math.random() * 1000, downloads: Math.random() * 10000, }); } // setTimeout(() => callback(data), delay); } .wj-flexgrid { max-height: 250px; } .wj-radialgauge.spinner { margin: auto auto; padding-bottom: 32px; max-width: 200px; } .spinner img, .spinner.wj-gauge { display: block; margin: auto; margin-top: 20px; } .btn { margin-bottom: 6px; } body { margin-bottom: 24pt; } import 'bootstrap.css'; import '@grapecity/wijmo.styles/wijmo.css'; import './styles.css'; // import { Component, Inject, enableProdMode, NgModule } from '@angular/core'; import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; import { BrowserModule } from '@angular/platform-browser'; import { DataService } from './app.data'; import { WjGridModule } from '@grapecity/wijmo.angular2.grid'; import { WjGaugeModule } from '@grapecity/wijmo.angular2.gauge'; // @Component({ selector: 'app-component', templateUrl: 'src/app.component.html' }) export class AppComponent { gifCtx = { loading: false, data: <any>null, } // gaugeCtx = { loading: false, data: <any>null, progress: 0, interval: <any>null } // constructor(@Inject(DataService) private dataService: DataService) { } // loadDataGif() { this.gifCtx.loading = true; this.dataService.getData((data) => { this.gifCtx.data = data; this.gifCtx.loading = false; }, 3000); } // loadDataGauge() { clearInterval(this.gaugeCtx.interval); // this.gaugeCtx.loading = true; this.gaugeCtx.progress = 0; this.gaugeCtx.interval = setInterval(() => { this.gaugeCtx.progress = (this.gaugeCtx.progress + 1) % 100; }, 50); // this.dataService.getData((data) => { clearInterval(this.gaugeCtx.interval); this.gaugeCtx.data = data; this.gaugeCtx.loading = false; }, 3000); } } // @NgModule({ imports: [WjGaugeModule, WjGridModule, 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 FlexGrid Spinners</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"> <h3> GIFスピナー</h3> <p> この例では、グリッドの読み込み中にアニメーションGIFを表示します。</p> <button class="btn btn-primary" (click)="loadDataGif()"> GIFスピナーを使用してグリッドを読み込む </button> <div> <div *ngIf="gifCtx.loading" class="spinner"> <img src="resources/Rounded%20blocks.gif"> </div> <wj-flex-grid *ngIf="!gifCtx.loading" [itemsSource]="gifCtx.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="sales" header="売上" [width]="80"></wj-flex-grid-column> <wj-flex-grid-column binding="downloads" header="DL数" [width]="80"></wj-flex-grid-column> </wj-flex-grid> </div> <h3> ゲージスピナー </h3> <p> この例では、グリッドの読み込み中にアニメーションRadialGaugeを表示します。</p> <button class="btn btn-primary" (click)="loadDataGauge()"> ゲージスピナーを使用してグリッドを読み込む </button> <div> <wj-radial-gauge *ngIf="gaugeCtx.loading" class="spinner" [isAnimated]="false" [showText]="'None'" [sweepAngle]="360" [step]="5" [showTicks]="true" [value]="gaugeCtx.progress"> <wj-range [wjProperty]="'face'" [color]="'transparent'"></wj-range> </wj-radial-gauge> <wj-flex-grid *ngIf="!gaugeCtx.loading" [itemsSource]="gaugeCtx.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="sales" header="売上" [width]="80"></wj-flex-grid-column> <wj-flex-grid-column binding="downloads" header="DL数" [width]="80"></wj-flex-grid-column> </wj-flex-grid> </div> </div> import { Injectable } from '@angular/core'; // @Injectable() export class DataService { getData(callback: (data: any[]) => void, delay: number) { let countries = ['アメリカ', 'イギリス', '中国', 'ドイツ', 'インド'], data: any[] = []; // for (let i = 0; i < 1000; i++) { data.push({ id: i, country: countries[i % countries.length], sales: Math.random() * 1000, downloads: Math.random() * 10000, }); } // setTimeout(() => callback(data), delay); } } .wj-flexgrid { max-height: 250px; } .wj-radialgauge.spinner { margin: auto auto; padding-bottom: 32px; max-width: 200px; } .spinner img, .spinner.wj-gauge { display: block; margin: auto; } .btn { margin-bottom: 6px; } body { margin-bottom: 24pt; } 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 wjGauge from '@grapecity/wijmo.react.gauge'; import { getData } from './data'; class App extends React.Component { render() { return <div className="container-fluid"> <h3>GIFスピナー</h3> <p>この例では、グリッドの読み込み中にアニメーションGIFを表示します。</p> <LoadingGridWithGif /> <h3>ゲージスピナー</h3> <p>この例では、グリッドの読み込み中にアニメーションRadialGaugeを表示します。</p> <LoadingGridWithGuage /> </div>; } } class LoadingGridWithGif extends React.Component { constructor(prop) { super(prop); this.state = { loading: false, data: undefined, }; } render() { return <div key={Date.now()}> <button className="btn btn-primary" onClick={this.loadData.bind(this)}> GIFスピナーを使用してグリッドを読み込む </button> {this.state.loading ? <div className="spinner"> <img src="resources/Rounded%20blocks.gif"/> </div> : <wjGrid.FlexGrid itemsSource={this.state.data}> <wjGrid.FlexGridColumn binding="id" header="ID" width={80}></wjGrid.FlexGridColumn> <wjGrid.FlexGridColumn binding="country" header="国"></wjGrid.FlexGridColumn> <wjGrid.FlexGridColumn binding="sales" header="売上" width={80}></wjGrid.FlexGridColumn> <wjGrid.FlexGridColumn binding="downloads" header="DL数" width={80}></wjGrid.FlexGridColumn> </wjGrid.FlexGrid>} </div>; } loadData() { this.setState({ loading: true }); getData((data) => { this.setState({ data, loading: false }); }, 3000); } } class LoadingGridWithGuage extends React.Component { constructor(prop) { super(prop); this.state = { loading: false, data: undefined, }; } render() { return <div key={Date.now()}> <button className="btn btn-primary" onClick={this.loadData.bind(this)}> ゲージスピナーを使用してグリッドを読み込む </button> {this.state.loading ? (<div><wjGauge.RadialGauge initialized={control => this._guage = control} className="spinner" isAnimated={false} showText="None" sweepAngle={360} step={5} showTicks={true} value={0}> <wjGauge.Range wjProperty="face" color="transparent"/> </wjGauge.RadialGauge></div>) : <wjGrid.FlexGrid itemsSource={this.state.data}> <wjGrid.FlexGridColumn binding="id" header="ID" width={80}></wjGrid.FlexGridColumn> <wjGrid.FlexGridColumn binding="country" header="国"></wjGrid.FlexGridColumn> <wjGrid.FlexGridColumn binding="sales" header="売上" width={80}></wjGrid.FlexGridColumn> <wjGrid.FlexGridColumn binding="downloads" header="DL数" width={80}></wjGrid.FlexGridColumn> </wjGrid.FlexGrid>} </div>; } loadData() { this.setState({ loading: true }); clearInterval(this._interval); this._interval = setInterval(() => { this._guage.value = (this._guage.value + 1) % 100; }, 50); getData((data) => { clearInterval(this._interval); this.setState({ data, loading: false }); }, 3000); } } 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: 250px; } .wj-radialgauge.spinner { margin: auto auto; padding-bottom: 32px; max-width: 200px; } .spinner img, .spinner.wj-gauge { display: block; margin: auto; } .btn { margin-bottom: 6px; } body { margin-bottom: 24pt; } export function getData(callback, delay) { let countries = ['アメリカ', 'イギリス', '中国', 'ドイツ', 'インド'], data = []; // for (let i = 0; i < 1000; i++) { data.push({ id: i, country: countries[i % countries.length], sales: Math.random() * 1000, downloads: Math.random() * 10000, }); } // setTimeout(() => callback(data), delay); } <template> <div class="container-fluid"> <h3> GIFスピナー</h3> <p> この例では、グリッドの読み込み中にアニメーションGIFを表示します。</p> <button class="btn btn-primary" v-on:click="loadDataGif"> GIFスピナーを使用してグリッドを読み込む </button> <div> <div v-if="gifCtx.loading" class="spinner"> <img src="resources/Rounded%20blocks.gif"> </div> <wj-flex-grid v-if="!gifCtx.loading" :items-source="gifCtx.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="sales" header="売上" :width=80></wj-flex-grid-column> <wj-flex-grid-column binding="downloads" header="DL数" :width=80></wj-flex-grid-column> </wj-flex-grid> </div> <h3> ゲージスピナー </h3> <p> この例では、グリッドの読み込み中にアニメーションRadialGaugeを表示します。</p> <button class="btn btn-primary" v-on:click="loadDataGauge"> ゲージスピナーを使用してグリッドを読み込む </button> <div> <wj-radial-gauge v-if="gaugeCtx.loading" class="spinner" :is-animated=false show-text="None" :sweep-angle=360 :step=5 :show-ticks=true :value="gaugeCtx.progress"> <wj-range wjProperty="face" color="transparent"></wj-range> </wj-radial-gauge> <wj-flex-grid v-if="!gaugeCtx.loading" :items-source="gaugeCtx.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="sales" header="売上" :width=80></wj-flex-grid-column> <wj-flex-grid-column binding="downloads" header="DL数" :width=80></wj-flex-grid-column> </wj-flex-grid> </div> </div> </template> <script> import "bootstrap.css"; import "@grapecity/wijmo.styles/wijmo.css"; import Vue from 'vue'; import * as wijmo from '@grapecity/wijmo.vue2.grid'; import '@grapecity/wijmo.vue2.gauge'; import { getData } from './data'; new Vue({ el: '#app', data: function () { return { gifCtx : { loading: false, data: null, }, gaugeCtx : { loading: false, data: null, progress: 0, interval: null } } }, methods:{ loadDataGif() { this.gifCtx.loading = true; getData((data) => { this.gifCtx.data = data; this.gifCtx.loading = false; }, 3000); }, loadDataGauge() { clearInterval(this.gaugeCtx.interval); // this.gaugeCtx.loading = true; this.gaugeCtx.progress = 0; this.gaugeCtx.interval = setInterval(() => { this.gaugeCtx.progress = (this.gaugeCtx.progress + 1) % 100; }, 50); // getData((data) => { clearInterval(this.gaugeCtx.interval); this.gaugeCtx.data = data; this.gaugeCtx.loading = false; }, 3000); } } }) </script> <style> .container-fluid .wj-flexgrid { max-height: 250px; } .wj-radialgauge.spinner { margin: auto auto; padding-bottom: 32px; max-width: 200px; } .spinner img, .spinner.wj-gauge { display: block; margin: auto; } .btn { margin-bottom: 6px; } body { margin-bottom: 24pt; } </style> <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <title>GrapeCity FlexGrid Spinners</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(callback, delay) { let countries = ['アメリカ', 'イギリス', '中国', 'ドイツ', 'インド'], data = []; // for (let i = 0; i < 1000; i++) { data.push({ id: i, country: countries[i % countries.length], sales: Math.random() * 1000, downloads: Math.random() * 10000, }); } // setTimeout(() => callback(data), delay); }