グリッド:ヘッダーセルの結合

FlexGridは、列ヘッダーセルのコンテンツ駆動型のセル結合をサポートしています。

import 'bootstrap.css'; import '@grapecity/wijmo.styles/wijmo.css'; import './styles.css'; import * as wjGrid from '@grapecity/wijmo.grid'; import { getData } from './data'; // document.readyState === 'complete' ? init() : window.onload = init; // function init() { // // grid with merged headers var theGrid = new wjGrid.FlexGrid('#theGrid', { allowMerging: 'ColumnHeaders', alternatingRowStep: 0, autoGenerateColumns: false, columns: [ { binding: 'country', header: '国', allowMerging: true }, { binding: 'sales', header: '売上', format: 'n2' }, { binding: 'expenses', header: '費用', format: 'n2' }, { binding: 'active', header: '有効', allowMerging: true }, ], itemsSource: getData() }); // // create extra header row var extraRow = new wjGrid.Row(); extraRow.allowMerging = true; // // add extra header row to the grid var panel = theGrid.columnHeaders; panel.rows.splice(0, 0, extraRow); // // populate the extra header row for (let colIndex = 1; colIndex <= 2; colIndex++) { panel.setCellData(0, colIndex, '金額'); } // // merge "Country" and "Active" headers vertically ['country', 'active'].forEach(function (binding) { let col = theGrid.getColumn(binding); col.allowMerging = true; panel.setCellData(0, col.index, col.header); }); // // center-align merged header cells theGrid.formatItem.addHandler(function (s, e) { if (e.panel == s.columnHeaders && e.range.rowSpan > 1) { var html = e.cell.innerHTML; e.cell.innerHTML = '<div class="v-center">' + html + '</div>'; } }); } <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <title>GrapeCity Wijmo FlexGrid Head Merging</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> </body> </html> // create some random data export function getData() { var countries = 'アメリカ,ドイツ,イギリス,日本'.split(','); var data = []; for (var i = 0; i < 20; i++) { data.push({ id: i, country: countries[i % countries.length], active: i % 5 != 0, downloads: Math.round(Math.random() * 200000), sales: Math.random() * 100000, expenses: Math.random() * 50000 }); } return data; } .wj-flexgrid { max-height: 200px; margin-bottom: 12px; } .wj-cell .v-center { position: relative; top: 50%; transform: translateY(-50%); white-space: pre-wrap; } body { margin-bottom: 24px; } import 'bootstrap.css'; import '@grapecity/wijmo.styles/wijmo.css'; import './styles.css'; // import * as wjCore from '@grapecity/wijmo'; import * as wjGrid 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 { DataService, DataItem } from './app.data'; // @Component({ selector: 'app-component', templateUrl: 'src/app.component.html' }) export class AppComponent { data: DataItem[]; // DataSvc will be passed by derived classes constructor(@Inject(DataService) private dataService: DataService) { this.data = dataService.getData(); } // onInitialized(grid: wjGrid.FlexGrid) { // create extra header row var extraRow = new wjGrid.Row(); extraRow.allowMerging = true; // // add extra header row to the grid var panel = grid.columnHeaders; panel.rows.splice(0, 0, extraRow); // // populate the extra header row for (let colIndex = 1; colIndex <= 2; colIndex++) { panel.setCellData(0, colIndex, '金額'); } // // merge "Country" and "Active" headers vertically ['country', 'active'].forEach(function (binding) { let col = grid.getColumn(binding); col.allowMerging = true; panel.setCellData(0, col.index, col.header); }); // // center-align merged header cells grid.formatItem.addHandler(function (s: wjGrid.FlexGrid, e: wjGrid.FormatItemEventArgs) { if (e.panel == s.columnHeaders && e.range.rowSpan > 1) { var html = e.cell.innerHTML; e.cell.innerHTML = '<div class="v-center">' + html + '</div>'; } }); } } //\\ @NgModule({ imports: [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 Wijmo FlexGrid Head Merging</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 #grid [itemsSource]="data" [allowMerging]="'ColumnHeaders'" [alternatingRowStep]="0" [autoGenerateColumns]="false" (initialized)="onInitialized(grid)"> <wj-flex-grid-column [binding]="'country'" [header]="'国'" [allowMerging]=true></wj-flex-grid-column> <wj-flex-grid-column [binding]="'sales'" [header]="'売上'" [format]="'n2'"></wj-flex-grid-column> <wj-flex-grid-column [binding]="'expenses'" [header]="'費用'" [format]="'n2'"></wj-flex-grid-column> <wj-flex-grid-column [binding]="'active'" [header]="'有効'" [allowMerging]=true></wj-flex-grid-column> </wj-flex-grid> </div> import { Injectable } from '@angular/core'; export interface DataItem { id: number; country: string; active: boolean; downloads: number; sales: number; expenses: number; } @Injectable() export class DataService { getData(): DataItem[] { var countries = 'アメリカ,ドイツ,イギリス,日本'.split(','); var data = []; for (var i = 0; i < 20; i++) { data.push({ id: i, country: countries[i % countries.length], active: i % 5 != 0, downloads: Math.round(Math.random() * 200000), sales: Math.random() * 100000, expenses: Math.random() * 50000 }); } return data; } } .wj-flexgrid { max-height: 200px; margin-bottom: 12px; } .wj-cell .v-center { position: relative; top: 50%; transform: translateY(-50%); white-space: pre-wrap; } body { margin-bottom: 24px; } 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 wjGrid from '@grapecity/wijmo.grid'; class App extends React.Component { render() { return <div className="container-fluid"> <wjcGrid.FlexGrid allowMerging="ColumnHeaders" alternatingRowStep={0} initialized={this.onInitialized.bind(this)}> <wjcGrid.FlexGridColumn binding="country" header="国" allowMerging={true}></wjcGrid.FlexGridColumn> <wjcGrid.FlexGridColumn binding="sales" header="売上" format="n2"></wjcGrid.FlexGridColumn> <wjcGrid.FlexGridColumn binding="expenses" header="費用" format="n2"></wjcGrid.FlexGridColumn> <wjcGrid.FlexGridColumn binding="active" header="有効" allowMerging={true}></wjcGrid.FlexGridColumn> </wjcGrid.FlexGrid> </div>; } onInitialized(grid) { // create extra header row var extraRow = new wjGrid.Row(); extraRow.allowMerging = true; // // add extra header row to the grid var panel = grid.columnHeaders; panel.rows.splice(0, 0, extraRow); // // populate the extra header row for (let colIndex = 1; colIndex <= 2; colIndex++) { panel.setCellData(0, colIndex, '金額'); } // // merge "Country" and "Active" headers vertically ['country', 'active'].forEach(function (binding) { let col = grid.getColumn(binding); col.allowMerging = true; panel.setCellData(0, col.index, col.header); }); // // center-align merged header cells grid.formatItem.addHandler(function (s, e) { if (e.panel == s.columnHeaders && e.range.rowSpan > 1) { var html = e.cell.innerHTML; e.cell.innerHTML = '<div class="v-center">' + html + '</div>'; } }); grid.autoGenerateColumns = false; grid.itemsSource = this.getData(); } getData() { var countries = 'アメリカ,ドイツ,イギリス,日本'.split(','); var data = []; for (var i = 0; i < 20; i++) { data.push({ id: i, country: countries[i % countries.length], active: i % 5 != 0, downloads: Math.round(Math.random() * 200000), sales: Math.random() * 100000, expenses: Math.random() * 50000 }); } return data; } } 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> .wj-flexgrid { max-height: 200px; margin-bottom: 12px; } .wj-cell .v-center { position: relative; top: 50%; transform: translateY(-50%); white-space: pre-wrap; } body { margin-bottom: 24px; } <template> <div class="container-fluid"> <wj-flex-grid :itemsSource="data" :allowMerging="'ColumnHeaders'" :alternatingRowStep="0" :autoGenerateColumns="false" :initialized="onInitialized" > <wj-flex-grid-column :binding="'country'" :header="'国'" :allowMerging="true"></wj-flex-grid-column> <wj-flex-grid-column :binding="'sales'" :header="'売上'" :format="'n2'"></wj-flex-grid-column> <wj-flex-grid-column :binding="'expenses'" :header="'費用'" :format="'n2'"></wj-flex-grid-column> <wj-flex-grid-column :binding="'active'" :header="'有効'" :allowMerging="true"></wj-flex-grid-column> </wj-flex-grid> </div> </template> <script> import "@grapecity/wijmo.styles/wijmo.css"; import "bootstrap.css"; import Vue from "vue"; import * as wjCore from "@grapecity/wijmo"; import * as wjGrid from '@grapecity/wijmo.grid'; import "@grapecity/wijmo.vue2.grid"; import { getData } from "./data"; let App = Vue.extend({ name: "app", data: function() { return { data: getData() }; }, methods: { onInitialized: function(grid) { // create extra header row var extraRow = new wjGrid.Row(); extraRow.allowMerging = true; // // add extra header row to the grid var panel = grid.columnHeaders; panel.rows.splice(0, 0, extraRow); // // populate the extra header row for (let colIndex = 1; colIndex <= 2; colIndex++) { panel.setCellData(0, colIndex, "金額"); } // // merge "Country" and "Active" headers vertically ["country", "active"].forEach(function(binding) { let col = grid.getColumn(binding); col.allowMerging = true; panel.setCellData(0, col.index, col.header); }); // // center-align merged header cells grid.formatItem.addHandler(function(s, e) { if (e.panel == s.columnHeaders && e.range.rowSpan > 1) { var html = e.cell.innerHTML; e.cell.innerHTML = '<div class="v-center">' + html + "</div>"; } }); } } }); new Vue({ render: h => h(App) }).$mount("#app"); </script> <style> .wj-flexgrid { max-height: 200px; margin-bottom: 12px; } .wj-cell .v-center { position: relative; top: 50%; transform: translateY(-50%); white-space: pre-wrap; } body { margin-bottom: 24px; } </style> <!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.vue'); </script> </head> <body> <div id="app"> </div> </body> </html> export function getData() { var countries = 'アメリカ,ドイツ,イギリス,日本'.split(','); var data = []; for (var i = 0; i < 20; i++) { data.push({ id: i, country: countries[i % countries.length], active: i % 5 != 0, downloads: Math.round(Math.random() * 200000), sales: Math.random() * 100000, expenses: Math.random() * 50000 }); } return data; }