高亮无效单元格

此示例显示如何在导出的文档中突出显示FlexGrid的无效单元格。

要在导出的文档中突出显示FlexGrid的无效单元格,应执行以下步骤:

  1. 确保已打开 FlexGrid.showErrors 属性。
  2. 指定 styles export设置的 errorCellStyle 属性。 此样式将应用于正在呈现的每个无效单元格。

注意:如果使用自定义单元格内容模式,则无需指定errorCellStyle属性。

在此示例中,以下代码突出显示淡红色的无效单元格:

wijmo.grid.pdf.FlexGridPdfConverter.export(flexGrid, 'FlexGrid.pdf', {
    styles: {
        errorCellStyle: {
            backgroundColor: 'rgba(255, 0, 0, 0.3)'
        }
    }
})
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: 'Country', binding: 'country' }, { header: 'Product', binding: 'product' }, { header: 'Amount', binding: 'amount', format: 'c' }, { header: 'Active', 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', { styles: { cellStyle: { 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"> FlexGrid Settings </h4> </div> <div class="panel-body"> <div class="form-check"> <label for="cbShowErrors" class="form-check-label">Show Errors</label> <input id="cbShowErrors" type="checkbox" checked="checked" /> </div> </div> </div> </div> <!-- Export button --> <button class="btn btn-default" id="btnExport">Export</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 ? 'Cannot be less than 1,000!' : null; case 'active': return item.active && item.country.match(/US|UK/) ? 'Active items are not allowed in the US or UK!' : null; } // return null; } }); } // function generateData(count) { // data used to generate random items const countries = ['US', 'Germany', 'UK', 'Japan', 'Italy', 'Greece']; const products = ['Widget', 'Gadget', 'Doohickey']; // 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', { styles: { cellStyle: { 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"> FlexGrid Settings </h4> </div> <div class="panel-body"> <div class="form-check"> <label for="cbShowErrors" class="form-check-label">Show Errors</label> <input id="cbShowErrors" type="checkbox" [(ngModel)]="flexGrid.showErrors" /> </div> </div> </div> </div> <!-- Export button --> <button class="btn btn-default" (click)="export()">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="Country" binding="country"></wj-flex-grid-column> <wj-flex-grid-column header="Product" binding="product"></wj-flex-grid-column> <wj-flex-grid-column header="Amount" binding="amount" format="c"></wj-flex-grid-column> <wj-flex-grid-column header="Active" 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 ? 'Cannot be less than 1,000!' : null; case 'active': return item.active && item.country.match(/US|UK/) ? 'Active items are not allowed in the US or UK!' : null; } // return null; } }); } // private generateData(count: number) { // data used to generate random items const countries = ['US', 'Germany', 'UK', 'Japan', 'Italy', 'Greece']; const products = ['Widget', 'Gadget', 'Doohickey']; // 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; } <template> <div class="container-fluid"> <!-- FlexGrid settings --> <div class="panel-group"> <div class="panel panel-default"> <div class="panel-heading"> <h4 class="panel-title"> FlexGrid Settings </h4> </div> <div class="panel-body"> <div class="form-check"> <label for="cbShowErrors" class="form-check-label">Show Errors</label> <input id="cbShowErrors" type="checkbox" v-model="showErrors" /> </div> </div> </div> </div> <!-- Export button --> <button class="btn btn-default" @click="exportPDF">Export</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="Country" binding="country"></wj-flex-grid-column> <wj-flex-grid-column header="Product" binding="product"></wj-flex-grid-column> <wj-flex-grid-column header="Amount" binding="amount" format="c"></wj-flex-grid-column> <wj-flex-grid-column header="Active" 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', { styles: { cellStyle: { 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 ? 'Cannot be less than 1,000!' : null; case 'active': return item.active && item.country.match(/US|UK/) ? 'Active items are not allowed in the US or UK!' : null; } // return null; } }); } function generateData(count) { // data used to generate random items const countries = ['US', 'Germany', 'UK', 'Japan', 'Italy', 'Greece']; const products = ['Widget', 'Gadget', 'Doohickey']; // 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; } 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"> FlexGrid Settings </h4> </div> <div className="panel-body"> <div className="form-check"> <label className="form-check-label"> Show Errors <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)}>Export</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="Country" binding="country"></wjcGrid.FlexGridColumn> <wjcGrid.FlexGridColumn header="Product" binding="product"></wjcGrid.FlexGridColumn> <wjcGrid.FlexGridColumn header="Amount" binding="amount" format="c"></wjcGrid.FlexGridColumn> <wjcGrid.FlexGridColumn header="Active" 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', { styles: { cellStyle: { 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 ? 'Cannot be less than 1,000!' : null; case 'active': return item.active && item.country.match(/US|UK/) ? 'Active items are not allowed in the US or UK!' : null; } // return null; } }); } function generateData(count) { // data used to generate random items const countries = ['US', 'Germany', 'UK', 'Japan', 'Italy', 'Greece']; const products = ['Widget', 'Gadget', 'Doohickey']; // 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; }