グリッド:行と列の固定

グリッドのfrozenRowsおよびfrozenColumnsプロパティを設定すると、行と列を固定できます。固定したセルはスクロールされず、通常のセルのように選択/編集できます。

import 'bootstrap.css'; import '@grapecity/wijmo.styles/wijmo.css'; import './styles.css'; import { FlexGrid } from '@grapecity/wijmo.grid'; document.readyState === 'complete' ? init() : window.onload = init; function init() { // generate some random data var countries = 'アメリカ,ドイツ,イギリス,日本,イタリア,ギリシャ'.split(','), data = []; for (var i = 0; i < 200; i++) { data.push({ id: i, country: countries[i % countries.length], downloads: Math.round(Math.random() * 20000), sales: Math.random() * 10000, expenses: Math.random() * 5000, num1: Math.random() * 5000, num2: Math.random() * 5000, num3: Math.random() * 5000, num4: Math.random() * 5000, num5: Math.random() * 5000, }); } // default behavior: allow column reordering var theGrid = new FlexGrid('#theGrid', { autoGenerateColumns: false, columns: [ { binding: 'id', header: 'ID', width: 80 }, { binding: 'country', header: '国' }, { binding: 'downloads', header: 'DL数', width: 80 }, { binding: 'sales', header: '売上', width: 80 }, { binding: 'expenses', header: '費用', width: 80 }, { binding: 'num1', header: '数値1', width: 80 }, { binding: 'num2', header: '数値2', width: 80 }, { binding: 'num3', header: '数値3', width: 80 }, { binding: 'num4', header: '数値4', width: 80 }, { binding: 'num5', header: '数値5', width: 80 }, ], itemsSource: data, frozenRows: 2, frozenColumns: 1 }); // toggle frozen rows document.getElementById('btnFreezeRows').addEventListener('click', function () { theGrid.frozenRows = theGrid.frozenRows > 0 ? 0 : 2; }); document.getElementById('btnFreezeCols').addEventListener('click', function () { theGrid.frozenColumns = theGrid.frozenColumns > 0 ? 0 : 1; }); } <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <title>GrapeCity Wijmo FlexGrid Frozen Rows and Columns</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> <button id="btnFreezeRows" class="btn btn-default"> 行の固定を切り替え </button> <button id="btnFreezeCols" class="btn btn-default"> 列の固定を切り替え </button> </div> </body> </html> .wj-flexgrid { max-height: 250px; margin: 10px 0; } body { margin-bottom: 20px; } /* style frozen cells */ .wj-cell.wj-frozen:not(.wj-header):not(.wj-group):not(.wj-state-selected):not(.wj-state-multi-selected), .wj-cell.wj-frozen.wj-alt:not(.wj-header):not(.wj-group):not(.wj-state-selected):not(.wj-state-multi-selected) { background: rgb(255,255,125); } import 'bootstrap.css'; import '@grapecity/wijmo.styles/wijmo.css'; import './styles.css'; // import { Component, enableProdMode, NgModule, ViewChild } from '@angular/core'; import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; import { BrowserModule } from '@angular/platform-browser'; import * as wjcGrid from '@grapecity/wijmo.grid'; import { WjGridModule } from '@grapecity/wijmo.angular2.grid'; // @Component({ selector: 'app-component', templateUrl: 'src/app.component.html' }) export class AppComponent { data: any[]; // DataSvc will be passed by derived classes constructor() { this.data = this._getData(); } @ViewChild('flex') grid: wjcGrid.FlexGrid; freezeRows() { this.grid.frozenRows = this.grid.frozenRows > 0 ? 0 : 2; } freezeColumns() { this.grid.frozenColumns = this.grid.frozenColumns > 0 ? 0 : 1; } private _getData() { // generate some random data let countries = 'アメリカ,ドイツ,イギリス,日本,イタリア,ギリシャ'.split(','), data = []; for (let i = 0; i < 200; i++) { data.push({ id: i, country: countries[i % countries.length], downloads: Math.round(Math.random() * 20000), sales: Math.random() * 10000, expenses: Math.random() * 5000, num1: Math.random() * 5000, num2: Math.random() * 5000, num3: Math.random() * 5000, num4: Math.random() * 5000, num5: Math.random() * 5000, }); } return data; } } // @NgModule({ imports: [WjGridModule, BrowserModule], 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 FlexGrid Frozen Rows and Columns</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 #flex [frozenRows]="2" [frozenColumns]="1" [(itemsSource)]="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="downloads" header="DL数" [width]="80"></wj-flex-grid-column> <wj-flex-grid-column binding="sales" header="売上" [width]="80"></wj-flex-grid-column> <wj-flex-grid-column binding="expenses" header="費用" [width]="80"></wj-flex-grid-column> <wj-flex-grid-column binding="num1" header="数値1" [width]="80"></wj-flex-grid-column> <wj-flex-grid-column binding="num2" header="数値2" [width]="80"></wj-flex-grid-column> <wj-flex-grid-column binding="num3" header="数値3" [width]="80"></wj-flex-grid-column> <wj-flex-grid-column binding="num4" header="数値4" [width]="80"></wj-flex-grid-column> <wj-flex-grid-column binding="num5" header="数値5" [width]="80"></wj-flex-grid-column> </wj-flex-grid> <div> <button (click)="freezeRows()" class="btn btn-default"> 行の固定を切り替え </button> <button (click)="freezeColumns()" class="btn btn-default"> 列の固定を切り替え </button> </div> </div> .wj-flexgrid { max-height: 250px; max-width: 800px; margin: 10px 0; } body { margin-bottom: 20px; } /* style frozen cells */ .wj-cell.wj-frozen:not(.wj-header):not(.wj-group):not(.wj-state-selected):not(.wj-state-multi-selected), .wj-cell.wj-frozen.wj-alt:not(.wj-header):not(.wj-group):not(.wj-state-selected):not(.wj-state-multi-selected) { background: rgb(255,255,125); } 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"; class App extends React.Component { constructor(props) { super(props); this.state = { grid: { data: this.getData(), frozenRows: 2, frozenColumns: 1 } }; } render() { return <div className="container-fluid"> <wjcGrid.FlexGrid id="sample-grid" frozenRows={this.state.grid.frozenRows} frozenColumns={this.state.grid.frozenColumns} itemsSource={this.state.grid.data} initialized={this._gridInitialized.bind(this)}> <wjcGrid.FlexGridColumn binding="id" header="ID" width={80}></wjcGrid.FlexGridColumn> <wjcGrid.FlexGridColumn binding="country" header="国"></wjcGrid.FlexGridColumn> <wjcGrid.FlexGridColumn binding="downloads" header="DL数" width={80}></wjcGrid.FlexGridColumn> <wjcGrid.FlexGridColumn binding="sales" header="売上" width={80}></wjcGrid.FlexGridColumn> <wjcGrid.FlexGridColumn binding="expenses" header="費用" width={80}></wjcGrid.FlexGridColumn> <wjcGrid.FlexGridColumn binding="num1" header="数値1" width={80}></wjcGrid.FlexGridColumn> <wjcGrid.FlexGridColumn binding="num2" header="数値2" width={80}></wjcGrid.FlexGridColumn> <wjcGrid.FlexGridColumn binding="num3" header="数値3" width={80}></wjcGrid.FlexGridColumn> <wjcGrid.FlexGridColumn binding="num4" header="数値4" width={80}></wjcGrid.FlexGridColumn> <wjcGrid.FlexGridColumn binding="num5" header="数値5" width={80}></wjcGrid.FlexGridColumn> </wjcGrid.FlexGrid> <div> <button onClick={this.freezeRows.bind(this)} className="btn btn-default"> 行の固定を切り替え </button> <button onClick={this.freezeColumns.bind(this)} className="btn btn-default"> 列の固定を切り替え </button> </div> </div>; } _gridInitialized(sender) { this._grid = sender; } freezeRows() { this._grid.frozenRows = this._grid.frozenRows > 0 ? 0 : 2; } freezeColumns() { this._grid.frozenColumns = this._grid.frozenColumns > 0 ? 0 : 1; } getData() { // generate some random data let countries = 'アメリカ,ドイツ,イギリス,日本,イタリア,ギリシャ'.split(','), data = []; for (let i = 0; i < 200; i++) { data.push({ id: i, country: countries[i % countries.length], downloads: Math.round(Math.random() * 20000), sales: Math.random() * 10000, expenses: Math.random() * 5000, num1: Math.random() * 5000, num2: Math.random() * 5000, num3: Math.random() * 5000, num4: Math.random() * 5000, num5: Math.random() * 5000 }); } 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 FlexGrid Frozen Rows and Columns</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; max-width: 800px; margin: 10px 0; } body { margin-bottom: 20px; } /* style frozen cells */ #sample-grid .wj-cell.wj-frozen:not(.wj-header):not(.wj-group):not(.wj-state-selected):not(.wj-state-multi-selected), #sample-grid .wj-cell.wj-frozen.wj-alt:not(.wj-header):not(.wj-group):not(.wj-state-selected):not(.wj-state-multi-selected) { background: rgb(255, 255, 125); } <template> <div class="container-fluid"> <wj-flex-grid id="sample-grid" :initialized="initData" :frozenRows="grid.frozenRows" :frozenColumns="grid.frozenColumns" :itemsSource="grid.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="downloads" header="DL数" :width=80></wj-flex-grid-column> <wj-flex-grid-column binding="sales" header="売上" :width=80></wj-flex-grid-column> <wj-flex-grid-column binding="expenses" header="費用" :width=80></wj-flex-grid-column> <wj-flex-grid-column binding="num1" header="数値1" :width=80></wj-flex-grid-column> <wj-flex-grid-column binding="num2" header="数値2" :width=80></wj-flex-grid-column> <wj-flex-grid-column binding="num3" header="数値3" :width=80></wj-flex-grid-column> <wj-flex-grid-column binding="num4" header="数値4" :width=80></wj-flex-grid-column> <wj-flex-grid-column binding="num5" header="数値5" :width=80></wj-flex-grid-column> </wj-flex-grid> <div> <button @click="freezeRows" class="btn btn-default"> 行の固定を切り替え </button> <button @click="freezeColumns" class="btn btn-default"> 列の固定を切り替え </button> </div> </div> </template> <script> import "@grapecity/wijmo.styles/wijmo.css"; import 'bootstrap.css'; import Vue from 'vue'; import '@grapecity/wijmo.vue2.core'; import '@grapecity/wijmo.vue2.grid'; let App = Vue.extend({ name: 'app', data: function(){ return { grid: { data: null, frozenRows: 2, frozenColumns: 1 } } }, methods: { freezeRows: function() { this.grid.frozenRows = this.grid.frozenRows > 0 ? 0 : 2; }, freezeColumns: function() { this.grid.frozenColumns = this.grid.frozenColumns > 0 ? 0 : 1; }, initData: function(){ this.grid.data = this.getData(); }, getData: function() { // generate some random data let countries = 'アメリカ,ドイツ,イギリス,日本,イタリア,ギリシャ'.split(','), data = []; for (let i = 0; i < 200; i++) { data.push({ id: i, country: countries[i % countries.length], downloads: Math.round(Math.random() * 20000), sales: Math.random() * 10000, expenses: Math.random() * 5000, num1: Math.random() * 5000, num2: Math.random() * 5000, num3: Math.random() * 5000, num4: Math.random() * 5000, num5: Math.random() * 5000, }); } return data; } } }) new Vue({ render: h => h(App) }).$mount('#app'); </script> <style> .wj-flexgrid { max-height: 250px; max-width: 800px; margin: 10px 0; } body { margin-bottom: 20px; } /* style frozen cells */ #sample-grid .wj-cell.wj-frozen:not(.wj-header):not(.wj-group):not(.wj-state-selected):not(.wj-state-multi-selected), #sample-grid .wj-cell.wj-frozen.wj-alt:not(.wj-header):not(.wj-group):not(.wj-state-selected):not(.wj-state-multi-selected) { background: rgb(255,255,125); } </style> <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <title>GrapeCity Wijmo FlexGrid Frozen Rows and Columns</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>