筛选

FlexSheet自定义 FlexGridFilter 扩展(wijmo.grid.filter.js)以处理每列的过滤。 当调用FlexSheet的 showColumnFilter( 方法时,它将显示所选列的过滤器UI。

import 'bootstrap.css'; import '@grapecity/wijmo.styles/wijmo.css'; import './styles.css'; import * as wjGrid from '@grapecity/wijmo.grid'; import * as wjFlexSheet from '@grapecity/wijmo.grid.sheet'; import { getData, getCountries, getProducts } from './data'; // document.readyState === 'complete' ? init() : window.onload = init; // function init() { let filteringSheet = new wjFlexSheet.FlexSheet('#filteringSheet'); filteringSheet.addBoundSheet('Country', getData(50)); filteringSheet.deferUpdate(() => { let column = filteringSheet.columns.getColumn('countryId'); if (column && !column.dataMap) { column.dataMap = buildDataMap(getCountries()); } column = filteringSheet.columns.getColumn('productId'); if (column && !column.dataMap) { column.dataMap = buildDataMap(getProducts()); } column = filteringSheet.columns.getColumn('amount'); if (column) { column.format = 'c2'; } }); document.querySelector('#showFilter').addEventListener('click', () => { filteringSheet.showColumnFilter(); }); // build a data map from a string array using the indices as keys function buildDataMap(items) { let map = []; for (let i = 0; i < items.length; i++) { map.push({ key: i, value: items[i] }); } return new wjGrid.DataMap(map, 'key', 'value'); } ; } <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <title>GrapeCity Wijmo FlexSheet Filtering</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="filteringSheet"></div> <button id="showFilter" type="button" class="btn btn-default">Show Filter</button> </div> </body> </html> let countries = ['US', 'Germany', 'UK', 'Japan', 'Italy', 'Greece'], products = ['Widget', 'Gadget', 'Doohickey']; export function getData(count) { let data = [], i = 0, countryId, productId; for (; i < count; i++) { countryId = Math.floor(Math.random() * countries.length); productId = Math.floor(Math.random() * products.length); data.push({ id: i, countryId: countryId, productId: productId, date: new Date(2014, i % 12, i % 28), amount: Math.random() * 10000, active: i % 4 === 0 }); } return data; } export function getCountries() { return countries; } export function getProducts() { return products; } .wj-flexsheet { height: 400px; margin: 6px 0; } import 'bootstrap.css'; import '@grapecity/wijmo.styles/wijmo.css'; import './styles.css'; import { Component, enableProdMode, NgModule, Inject, ViewChild } from '@angular/core'; import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; import { BrowserModule } from '@angular/platform-browser'; import { WjGridSheetModule } from '@grapecity/wijmo.angular2.grid.sheet'; import * as wjcGrid from '@grapecity/wijmo.grid'; import * as wjcSheet from '@grapecity/wijmo.grid.sheet'; import { DataService } from './app.data'; @Component({ selector: 'app-component', templateUrl: 'src/app.component.html' }) export class AppComponent { data: any[]; private _countries: string[]; private _products: string[]; constructor(@Inject(DataService) dataSvc: DataService) { this.data = dataSvc.getData(50); this._countries = dataSvc.countries; this._products = dataSvc.products; } @ViewChild('flex') flex: wjcSheet.FlexSheet; initializeFlexSheet(flex: wjcSheet.FlexSheet) { flex.deferUpdate(() => { let column = flex.columns.getColumn('countryId'); if (column && !column.dataMap) { column.dataMap = this._buildDataMap(this._countries); } column = flex.columns.getColumn('productId'); if (column && !column.dataMap) { column.dataMap = this._buildDataMap(this._products); } column = flex.columns.getColumn('amount'); if (column) { column.format = 'c2'; } }); } showFilter() { this.flex.showColumnFilter(); } // build a data map from a string array using the indices as keys private _buildDataMap(items: string[]) { let map = []; for (let i = 0; i < items.length; i++) { map.push({ key: i, value: items[i] }); } return new wjcGrid.DataMap(map, 'key', 'value'); }; } @NgModule({ imports: [WjGridSheetModule, BrowserModule], providers: [DataService], declarations: [AppComponent], 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 Wijmo FlexSheet Filtering</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"> <!-- the flexsheet --> <wj-flex-sheet #flex (initialized)="initializeFlexSheet(flex)"> <wj-sheet [name]="'Country'" [(itemsSource)]="data"></wj-sheet> </wj-flex-sheet> <button (click)="showFilter()" type="button" class="btn btn-default">Show Filter</button> </div> import { Injectable } from '@angular/core'; @Injectable() export class DataService { countries = ['US', 'Germany', 'UK', 'Japan', 'Italy', 'Greece']; products = ['Widget', 'Gadget', 'Doohickey']; getData(count: number) { let data = [], i = 0, countryId, productId; for (; i < count; i++) { countryId = Math.floor(Math.random() * this.countries.length); productId = Math.floor(Math.random() * this.products.length); data.push({ id: i, countryId: countryId, productId: productId, date: new Date(2014, i % 12, i % 28), amount: Math.random() * 10000, active: i % 4 === 0 }); } return data; } } .wj-flexsheet { height: 400px; margin: 6px 0; } <template> <div class="container-fluid"> <!-- the flexsheet --> <wj-flex-sheet :initialized="initializeFlexSheet"> <wj-sheet :name="'Country'" :itemsSource="data"></wj-sheet> </wj-flex-sheet> <button @click="showFilter" type="button" class="btn btn-default">Show Filter</button> </div> </template> <script> import "@grapecity/wijmo.styles/wijmo.css"; import "bootstrap.css"; import Vue from "vue"; import "@grapecity/wijmo.vue2.grid.sheet"; import * as wjcGrid from '@grapecity/wijmo.grid'; import { getData, getCountries, getProducts } from "./data"; let App = Vue.extend({ name: "app", data: function() { return { data: getData(50), products: getProducts(), countries: getCountries(), flex: null }; }, methods: { initializeFlexSheet: function(flex) { flex.deferUpdate(() => { let column = flex.columns.getColumn("countryId"); if (column && !column.dataMap) { column.dataMap = this._buildDataMap(this.countries); } column = flex.columns.getColumn("productId"); if (column && !column.dataMap) { column.dataMap = this._buildDataMap(this.products); } column = flex.columns.getColumn("amount"); if (column) { column.format = "c2"; } }); this.flex = flex; }, showFilter: function() { this.flex.showColumnFilter(); }, _buildDataMap: function(items) { let map = []; for (let i = 0; i < items.length; i++) { map.push({ key: i, value: items[i] }); } return new wjcGrid.DataMap(map, "key", "value"); } } }); new Vue({ render: h => h(App) }).$mount("#app"); </script> <style> .container-fluid .wj-flexsheet { height: 400px; margin: 6px 0; } </style> <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <title>GrapeCity Wijmo FlexSheet Filtering</title> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <!-- SystemJS --> <script src="node_modules/jszip/dist/jszip.js"></script> <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> let countries = ['US', 'Germany', 'UK', 'Japan', 'Italy', 'Greece'], products = ['Widget', 'Gadget', 'Doohickey']; export function getData(count) { let data = [], i = 0, countryId, productId; for (; i < count; i++) { countryId = Math.floor(Math.random() * countries.length); productId = Math.floor(Math.random() * products.length); data.push({ id: i, countryId: countryId, productId: productId, date: new Date(2014, i % 12, i % 28), amount: Math.random() * 10000, active: i % 4 === 0 }); } return data; } export function getCountries() { return countries; } export function getProducts() { return products; } import './app.css'; import 'bootstrap.css'; import '@grapecity/wijmo.styles/wijmo.css'; // import * as React from 'react'; import * as ReactDOM from 'react-dom'; import * as wjcGrid from "@grapecity/wijmo.grid"; import * as wjGridSheet from "@grapecity/wijmo.react.grid.sheet"; import { getData, getCountries, getProducts } from "./data"; class App extends React.Component { constructor(props) { super(props); this.state = { data: getData(50), products: getProducts(), countries: getCountries(), flex: null }; } initializeFlexSheet(flex) { flex.deferUpdate(() => { let column = flex.columns.getColumn("countryId"); if (column && !column.dataMap) { column.dataMap = this._buildDataMap(this.state.countries); } column = flex.columns.getColumn("productId"); if (column && !column.dataMap) { column.dataMap = this._buildDataMap(this.state.products); } column = flex.columns.getColumn("amount"); if (column) { column.format = "c2"; } }); this.setState({ flex: flex }); } showFilter() { this.state.flex.showColumnFilter(); } _buildDataMap(items) { let map = []; for (let i = 0; i < items.length; i++) { map.push({ key: i, value: items[i] }); } return new wjcGrid.DataMap(map, "key", "value"); } render() { return (<div className="container-fluid"> <wjGridSheet.FlexSheet initialized={this.initializeFlexSheet.bind(this)}> <wjGridSheet.Sheet name="Country" itemsSource={this.state.data}></wjGridSheet.Sheet> </wjGridSheet.FlexSheet> <button onClick={this.showFilter.bind(this)} type="button" className="btn btn-default">Show Filter</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> .container-fluid .wj-flexsheet { height: 400px; margin: 6px 0; } let countries = ['US', 'Germany', 'UK', 'Japan', 'Italy', 'Greece'], products = ['Widget', 'Gadget', 'Doohickey']; export function getData(count) { let data = [], i = 0, countryId, productId; for (; i < count; i++) { countryId = Math.floor(Math.random() * countries.length); productId = Math.floor(Math.random() * products.length); data.push({ id: i, countryId: countryId, productId: productId, date: new Date(2014, i % 12, i % 28), amount: Math.random() * 10000, active: i % 4 === 0 }); } return data; } export function getCountries() { return countries; } export function getProducts() { return products; }