グリッド:無効なセルの強調表示

このサンプルでは、エクスポートされたドキュメントでFlexGridの無効なセルを強調表示する方法を示します。

import 'bootstrap.css'; import '@grapecity/wijmo.styles/wijmo.css'; import './styles.css'; import * as grid from '@grapecity/wijmo.grid'; import * as gridPdf from '@grapecity/wijmo.grid.pdf'; import { getData } from './data'; // document.readyState === 'complete' ? init() : window.onload = init; // function init() { let flexGrid = new grid.FlexGrid('#flexGrid', { autoGenerateColumns: false, selectionMode: grid.SelectionMode.ListBox, headersVisibility: grid.HeadersVisibility.All, showErrors: true, columns: [ { header: 'ID', binding: 'id' }, { header: '国', binding: 'country' }, { header: '商品', binding: 'product' }, { header: '金額', binding: 'amount', format: 'c' }, { header: '有効', binding: 'active' } ], itemsSource: getData(10) }); // document.querySelector('#cbShowErrors').addEventListener('change', (e) => { flexGrid.showErrors = e.target.checked; }); // document.querySelector('#btnExport').addEventListener('click', () => { gridPdf.FlexGridPdfConverter.export(flexGrid, 'FlexGrid.pdf', { embeddedFonts: [{ source: 'https://demo.grapecity.com/wijmo/sample/fonts/ipaexg.ttf', name: 'ipaexg' }], styles: { cellStyle: { font: { family: 'ipaexg' }, backgroundColor: '#ffffff', borderColor: '#c6c6c6' }, altCellStyle: { backgroundColor: '#f9f9f9' }, groupCellStyle: { backgroundColor: '#dddddd' }, headerCellStyle: { backgroundColor: '#eaeaea' }, errorCellStyle: { backgroundColor: 'rgba(255, 0, 0, 0.3)' } } }); }); } <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <title>Highlight invalid cells</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"> <!-- FlexGrid settings --> <div class="panel-group"> <div class="panel panel-default"> <div class="panel-heading"> <h4 class="panel-title"> 設定 </h4> </div> <div class="panel-body"> <div class="form-check"> <label for="cbShowErrors" class="form-check-label">エラーを表示</label> <input id="cbShowErrors" type="checkbox" checked="checked" /> </div> </div> </div> </div> <!-- Export button --> <button class="btn btn-default" id="btnExport">エクスポート</button> <!-- FlexGrid --> <div id="flexGrid" class="grid"></div> </div> </body> </html> import { CollectionView } from '@grapecity/wijmo'; // export function getData(count) { return new CollectionView(generateData(count), { getError: (item, property) => { switch (property) { case 'amount': return item.amount < 1000 ? '金額を1,000以下にはできません。' : null; case 'active': return item.active && item.country.match(/アメリカ|イギリス/) ? 'アメリカとイギリスでは有効にできません。' : null; } // return null; } }); } // function generateData(count) { // data used to generate random items const countries = ['アメリカ', 'ドイツ', 'イギリス', '日本', 'イタリア', 'ギリシャ']; const products = ['ウィジェット', 'ガジェット', 'ツール']; // let data = []; // // add count items for (let i = 0; i < count; i++) { // constants used to create data items let countryId = Math.floor(Math.random() * countries.length), productId = Math.floor(Math.random() * products.length); // // create the item let item = { id: i, country: countries[countryId], product: products[productId], amount: Math.random() * 10000 - 5000, active: i % 4 == 0 }; // // add the item to the list data.push(item); } // return data; } body { margin-bottom: 24px; } .grid { margin-top: 20px; height: 300px; } label { margin-right: 3px; } import 'bootstrap.css'; import '@grapecity/wijmo.styles/wijmo.css'; import './styles.css'; // import * as wijmo from '@grapecity/wijmo'; import * as grid from '@grapecity/wijmo.grid'; import * as gridPdf from '@grapecity/wijmo.grid.pdf'; // import { Component, Inject, enableProdMode, NgModule, ViewChild } from '@angular/core'; import { FormsModule } from '@angular/forms'; 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'; // @Component({ selector: 'app-component', templateUrl: 'src/app.component.html' }) export class AppComponent { data: wijmo.CollectionView; @ViewChild('flexGrid') flexGrid: grid.FlexGrid; // constructor(@Inject(DataService) private dataService: DataService) { this.data = dataService.getData(10); } // export() { gridPdf.FlexGridPdfConverter.export(this.flexGrid, 'FlexGrid.pdf', { embeddedFonts: [{ source: 'https://demo.grapecity.com/wijmo/sample/fonts/ipaexg.ttf', name: 'ipaexg' }], styles: { cellStyle: { font: { family: 'ipaexg' }, backgroundColor: '#ffffff', borderColor: '#c6c6c6' }, altCellStyle: { backgroundColor: '#f9f9f9' }, groupCellStyle: { backgroundColor: '#dddddd' }, headerCellStyle: { backgroundColor: '#eaeaea' }, errorCellStyle: { backgroundColor: 'rgba(255, 0, 0, 0.3)' } } }); } } // @NgModule({ imports: [WjGridModule, BrowserModule, FormsModule], 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>Highlight invalid cells</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"> <!-- FlexGrid settings --> <div class="panel-group"> <div class="panel panel-default"> <div class="panel-heading"> <h4 class="panel-title"> 設定 </h4> </div> <div class="panel-body"> <div class="form-check"> <label for="cbShowErrors" class="form-check-label">エラーを表示</label> <input id="cbShowErrors" type="checkbox" [(ngModel)]="flexGrid.showErrors" /> </div> </div> </div> </div> <!-- Export button --> <button class="btn btn-default" (click)="export()">エクスポート</button> <!-- FlexGrid --> <wj-flex-grid class="grid" #flexGrid [autoGenerateColumns]="false" selectionMode="ListBox" headersVisibility="All" [showErrors]="true" [itemsSource]="data"> <wj-flex-grid-column header="ID" binding="id"></wj-flex-grid-column> <wj-flex-grid-column header="国" binding="country"></wj-flex-grid-column> <wj-flex-grid-column header="商品" binding="product"></wj-flex-grid-column> <wj-flex-grid-column header="金額" binding="amount" format="c"></wj-flex-grid-column> <wj-flex-grid-column header="有効" binding="active"></wj-flex-grid-column> </wj-flex-grid> </div> import { Injectable } from '@angular/core'; import { CollectionView } from '@grapecity/wijmo'; // @Injectable() export class DataService { getData(count: number) { return new CollectionView(this.generateData(count), { getError: (item: { country: string, amount: number, active: boolean }, property: string) => { switch (property) { case 'amount': return item.amount < 1000 ? '金額を1,000以下にはできません。' : null; case 'active': return item.active && item.country.match(/アメリカ|イギリス/) ? 'アメリカとイギリスでは有効にできません。' : null; } // return null; } }); } // private generateData(count: number) { // data used to generate random items const countries = ['アメリカ', 'ドイツ', 'イギリス', '日本', 'イタリア', 'ギリシャ']; const products = ['ウィジェット', 'ガジェット', 'ツール']; // let data = []; // // add count items for (let i = 0; i < count; i++) { // constants used to create data items let countryId = Math.floor(Math.random() * countries.length), productId = Math.floor(Math.random() * products.length); // // create the item let item = { id: i, country: countries[countryId], product: products[productId], amount: Math.random() * 10000 - 5000, active: i % 4 == 0 }; // // add the item to the list data.push(item); } // return data; } } body { margin-bottom: 24px; } .grid { margin-top: 20px; height: 300px; } label { margin-right: 3px; } import "@grapecity/wijmo.styles/wijmo.css"; import "bootstrap.css"; import "./app.css"; // import * as React from 'react'; import * as ReactDOM from 'react-dom'; // import * as wjcGrid from "@grapecity/wijmo.react.grid"; import * as gridPdf from "@grapecity/wijmo.grid.pdf"; import { getData } from "./data"; class App extends React.Component { constructor(props) { super(props); this.state = { data: getData(10), showErrors: true }; } render() { return <div className="container-fluid"> <div className="panel-group"> <div className="panel panel-default"> <div className="panel-heading"> <h4 className="panel-title"> 設定 </h4> </div> <div className="panel-body"> <div className="form-check"> <label className="form-check-label"> エラーを表示 <input id="cbShowErrors" type="checkbox" checked={this.state.showErrors} onChange={this.showErrorChanged.bind(this)}/> </label> </div> </div> </div> </div> <button className="btn btn-default" onClick={this.exportPDF.bind(this)}>エクスポート</button> <wjcGrid.FlexGrid className="grid" autoGenerateColumns={false} selectionMode="ListBox" headersVisibility="All" showErrors={this.state.showErrors} itemsSource={this.state.data} initialized={this.initializeGrid.bind(this)}> <wjcGrid.FlexGridColumn header="ID" binding="id"></wjcGrid.FlexGridColumn> <wjcGrid.FlexGridColumn header="国" binding="country"></wjcGrid.FlexGridColumn> <wjcGrid.FlexGridColumn header="商品" binding="product"></wjcGrid.FlexGridColumn> <wjcGrid.FlexGridColumn header="金額" binding="amount" format="c"></wjcGrid.FlexGridColumn> <wjcGrid.FlexGridColumn header="有効" binding="active"></wjcGrid.FlexGridColumn> </wjcGrid.FlexGrid> </div>; } initializeGrid(ctl) { this.flexGrid = ctl; } showErrorChanged() { this.setState({ showErrors: !this.state.showErrors }); } exportPDF() { gridPdf.FlexGridPdfConverter.export(this.flexGrid, 'FlexGrid.pdf', { embeddedFonts: [{ source: 'https://demo.grapecity.com/wijmo/sample/fonts/ipaexg.ttf', name: 'ipaexg' }], styles: { cellStyle: { font: { family: 'ipaexg' }, backgroundColor: '#ffffff', borderColor: '#c6c6c6' }, altCellStyle: { backgroundColor: '#f9f9f9' }, groupCellStyle: { backgroundColor: '#dddddd' }, headerCellStyle: { backgroundColor: '#eaeaea' }, errorCellStyle: { backgroundColor: 'rgba(255, 0, 0, 0.3)' } } }); } } 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 OLAP Pivot Chart Overview</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> body { margin-bottom: 24px; } .grid { margin-top: 20px; height: 300px; } #cbShowErrors { margin: 5px; vertical-align: middle; } import { CollectionView } from '@grapecity/wijmo'; export function getData(count) { return new CollectionView(generateData(count), { getError: (item, property) => { switch (property) { case 'amount': return item.amount < 1000 ? '金額を1,000以下にはできません。' : null; case 'active': return item.active && item.country.match(/アメリカ|イギリス/) ? 'アメリカとイギリスでは有効にできません。' : null; } // return null; } }); } function generateData(count) { // data used to generate random items const countries = ['アメリカ', 'ドイツ', 'イギリス', '日本', 'イタリア', 'ギリシャ']; const products = ['ウィジェット', 'ガジェット', 'ツール']; // let data = []; // // add count items for (let i = 0; i < count; i++) { // constants used to create data items let countryId = Math.floor(Math.random() * countries.length), productId = Math.floor(Math.random() * products.length); // // create the item let item = { id: i, country: countries[countryId], product: products[productId], amount: Math.random() * 10000 - 5000, active: i % 4 == 0 }; // // add the item to the list data.push(item); } // return data; } <template> <div class="container-fluid"> <!-- FlexGrid settings --> <div class="panel-group"> <div class="panel panel-default"> <div class="panel-heading"> <h4 class="panel-title"> 設定 </h4> </div> <div class="panel-body"> <div class="form-check"> <label for="cbShowErrors" class="form-check-label">エラーを表示</label> <input id="cbShowErrors" type="checkbox" v-model="showErrors" /> </div> </div> </div> </div> <!-- Export button --> <button class="btn btn-default" @click="exportPDF">エクスポート</button> <!-- FlexGrid --> <wj-flex-grid class="grid" :autoGenerateColumns=false selectionMode="ListBox" headersVisibility="All" :showErrors="showErrors" :itemsSource="data" :initialized="initializeGrid"> <wj-flex-grid-column header="ID" binding="id"></wj-flex-grid-column> <wj-flex-grid-column header="国" binding="country"></wj-flex-grid-column> <wj-flex-grid-column header="商品" binding="product"></wj-flex-grid-column> <wj-flex-grid-column header="金額" binding="amount" format="c"></wj-flex-grid-column> <wj-flex-grid-column header="有効" binding="active"></wj-flex-grid-column> </wj-flex-grid> </div> </template> <script> import 'bootstrap.css'; import '@grapecity/wijmo.styles/wijmo.css'; import Vue from 'vue'; import { getData } from './data'; import * as wijmo from '@grapecity/wijmo'; import * as gridPdf from '@grapecity/wijmo.grid.pdf'; import { WjGridModule } from '@grapecity/wijmo.vue2.grid'; new Vue({ el: '#app', data: { data: getData(10), showErrors: true }, methods: { initializeGrid(ctl) { this.flexGrid = ctl; }, exportPDF() { gridPdf.FlexGridPdfConverter.export(this.flexGrid, 'FlexGrid.pdf', { embeddedFonts: [{ source: 'https://demo.grapecity.com/wijmo/sample/fonts/ipaexg.ttf', name: 'ipaexg' }], styles: { cellStyle: { font: { family: 'ipaexg' }, backgroundColor: '#ffffff', borderColor: '#c6c6c6' }, altCellStyle: { backgroundColor: '#f9f9f9' }, groupCellStyle: { backgroundColor: '#dddddd' }, headerCellStyle: { backgroundColor: '#eaeaea' }, errorCellStyle: { backgroundColor: 'rgba(255, 0, 0, 0.3)' } } }); } } }); </script> <style> body { margin-bottom: 24px; } .grid { margin-top: 20px; height: 300px; } </style> <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <title>Highlight invalid cells</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> import { CollectionView } from '@grapecity/wijmo'; export function getData(count) { return new CollectionView(generateData(count), { getError: (item, property) => { switch (property) { case 'amount': return item.amount < 1000 ? '金額を1,000以下にはできません。' : null; case 'active': return item.active && item.country.match(/アメリカ|イギリス/) ? 'アメリカとイギリスでは有効にできません。' : null; } // return null; } }); } function generateData(count) { // data used to generate random items const countries = ['アメリカ', 'ドイツ', 'イギリス', '日本', 'イタリア', 'ギリシャ']; const products = ['ウィジェット', 'ガジェット', 'ツール']; // let data = []; // // add count items for (let i = 0; i < count; i++) { // constants used to create data items let countryId = Math.floor(Math.random() * countries.length), productId = Math.floor(Math.random() * products.length); // // create the item let item = { id: i, country: countries[countryId], product: products[productId], amount: Math.random() * 10000 - 5000, active: i % 4 == 0 }; // // add the item to the list data.push(item); } // return data; }