响应式

此FlexGrid显示大型设备上的所有列,并且在具有窄屏幕的设备上仅显示一个摘要列:

import 'bootstrap.css'; import '@grapecity/wijmo.styles/wijmo.css'; import './styles.css'; import * as wjGrid from '@grapecity/wijmo.grid'; import * as wjCore from '@grapecity/wijmo'; // document.readyState === 'complete' ? init() : window.onload = init; // function init() { // // create the grid var theGrid = new wjGrid.FlexGrid('#theGrid', { autoGenerateColumns: false, headersVisibility: 'Column', columns: [ { header: "Company", isReadOnly: true, visible: false, allowDragging: false, width: "*" }, { header: "Company Name", binding: "CompanyName", width: "20*" }, { header: "Contact Name", binding: "ContactName", width: "15*" }, { header: "Contact Title", binding: "ContactTitle", width: "20*" }, { header: "Address", binding: "Address", width: "20*" }, { header: "City", binding: "City", width: "10*" }, { header: "Country", binding: "Country", width: "15*" } ], formatItem: function (s, e) { if (e.panel == s.cells && e.col == 0) { var html = wjCore.format('<div class="item-header">{CompanyName}</div>' + '<div class="item-detail">{ContactName}, {ContactTitle}</div>' + '<div class="item-detail">{Address}, {City}, {Country}</div>', s.rows[e.row].dataItem); e.cell.innerHTML = html; } } }); // // store default row height var defaultRowHeight = theGrid.rows.defaultSize; // // make it responsive theGrid.addEventListener(window, 'resize', updateGridLayout); function updateGridLayout() { // // show/hide columns var narrow = theGrid.hostElement.clientWidth < 600; theGrid.columns.forEach(function (col) { col.visible = col.index == 0 ? narrow : !narrow; }); // // make rows taller on phone layout theGrid.rows.defaultSize = defaultRowHeight * (narrow ? 3 : 1); // // hide column headers on narrow layouts theGrid.headersVisibility = narrow ? wjGrid.HeadersVisibility.None : wjGrid.HeadersVisibility.Column; } // // get some data wjCore.httpRequest('https://services.odata.org/Northwind/Northwind.svc/Customers?$format=json', { success: function (xhr) { var response = JSON.parse(xhr.responseText); theGrid.itemsSource = response.value; updateGridLayout(); } }); // } <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <title>GrapeCity Wijmo FlexGrid Responsive Layouts</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> /* set grid height */ .wj-flexgrid { height: 350px; -moz-user-select: none; } /* disable alternating rows */ .wj-alt:not(.wj-header):not(.wj-group):not(.wj-state-selected):not(.wj-state-multi-selected) { background: #fff; } /* format detail cells */ .item-header { font-weight: bold; font-size: 150%; } .item-detail { margin-left: 12px; } 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 { WjGridModule } from '@grapecity/wijmo.angular2.grid'; import * as wjcCore from '@grapecity/wijmo'; import * as wjcGrid from '@grapecity/wijmo.grid'; @Component({ selector: 'app-component', templateUrl: 'src/app.component.html' }) export class AppComponent { private _defaultRowHeight: number; @ViewChild('flex') flex: wjcGrid.FlexGrid; ngAfterViewInit() { // get some data wjcCore.httpRequest('https://services.odata.org/Northwind/Northwind.svc/Customers?$format=json', { success: (xhr: XMLHttpRequest) => { let response = JSON.parse(xhr.responseText); this.flex.itemsSource = response.value; this._updateGridLayout(); } }); this._defaultRowHeight = this.flex.rows.defaultSize; this.flex.addEventListener(window, 'resize', this._updateGridLayout.bind(this)); } initializeGrid(flex: wjcGrid.FlexGrid) { flex.formatItem.addHandler((s: wjcGrid.FlexGrid, e: wjcGrid.FormatItemEventArgs) => { // show company summary on narrow layout if (e.panel == s.cells && e.col == 0) { let html = wjcCore.format('<div class="item-header">{CompanyName}</div>' + '<div class="item-detail">{ContactName}, {ContactTitle}</div>' + '<div class="item-detail">{Address}, {City}, {Country}</div>', s.rows[e.row].dataItem); e.cell.innerHTML = html; } }); } private _updateGridLayout() { // show/hide columns let narrow = this.flex.hostElement.clientWidth < 600; this.flex.columns.forEach((col: wjcGrid.Column) => { col.visible = col.index == 0 ? narrow : !narrow; }); // make rows taller on phone layout this.flex.rows.defaultSize = this._defaultRowHeight * (narrow ? 3 : 1); // hide column headers on narrow layouts this.flex.headersVisibility = narrow ? wjcGrid.HeadersVisibility.None : wjcGrid.HeadersVisibility.Column; } } @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 Responsive Layouts</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 grid --> <wj-flex-grid #flex [headersVisibility]="'Column'" [(itemsSource)]="data" (initialized)="initializeGrid(flex)"> <wj-flex-grid-column [header]="'Company'" [visible]="false" [width]="'*'" [isReadOnly]="true" [allowDragging]="false"></wj-flex-grid-column> <wj-flex-grid-column [binding]="'CompanyName'" [header]="'Company Name'" [width]="'20*'"></wj-flex-grid-column> <wj-flex-grid-column [binding]="'ContactName'" [header]="'Contact Name'" [width]="'15*'"></wj-flex-grid-column> <wj-flex-grid-column [binding]="'ContactTitle'" [header]="'Contact Title'" [width]="'20*'"></wj-flex-grid-column> <wj-flex-grid-column [binding]="'Address'" [header]="'Address'" [width]="'20*'"></wj-flex-grid-column> <wj-flex-grid-column [binding]="'City'" [header]="'City'" [width]="'10*'"></wj-flex-grid-column> <wj-flex-grid-column [binding]="'Country'" [header]="'Country'" [width]="'15*'"></wj-flex-grid-column> </wj-flex-grid> </div> /* set grid height */ .wj-flexgrid { height: 350px; -moz-user-select: none; } /* disable alternating rows */ .wj-alt:not(.wj-header):not(.wj-group):not(.wj-state-selected):not(.wj-state-multi-selected) { background: #fff; } /* format detail cells */ .item-header { font-weight: bold; font-size: 150%; } .item-detail { margin-left: 12px; } <template> <div class="container-fluid"> <!-- the grid --> <wj-flex-grid :headersVisibility="'Column'" :initialized="initializeGrid" > <wj-flex-grid-column :header="'Company'" :visible="false" :width="'*'" :isReadOnly="true" :allowDragging="false" ></wj-flex-grid-column> <wj-flex-grid-column :binding="'CompanyName'" :header="'Company Name'" :width="'20*'"></wj-flex-grid-column> <wj-flex-grid-column :binding="'ContactName'" :header="'Contact Name'" :width="'15*'"></wj-flex-grid-column> <wj-flex-grid-column :binding="'ContactTitle'" :header="'Contact Title'" :width="'20*'"></wj-flex-grid-column> <wj-flex-grid-column :binding="'Address'" :header="'Address'" :width="'20*'"></wj-flex-grid-column> <wj-flex-grid-column :binding="'City'" :header="'City'" :width="'10*'"></wj-flex-grid-column> <wj-flex-grid-column :binding="'Country'" :header="'Country'" :width="'15*'"></wj-flex-grid-column> </wj-flex-grid> </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"; import * as wjcGrid from "@grapecity/wijmo.grid"; let App = Vue.extend({ name: "app", data: function() { return { flex: null, _defaultRowHeight: 0 }; }, methods: { initializeGrid: function(flex) { flex.formatItem.addHandler((s, e) => { // show company summary on narrow layout if (e.panel == s.cells && e.col == 0) { let html = wijmo.format( '<div class="item-header">{CompanyName}</div>' + '<div class="item-detail">{ContactName}, {ContactTitle}</div>' + '<div class="item-detail">{Address}, {City}, {Country}</div>', s.rows[e.row].dataItem ); e.cell.innerHTML = html; } }); this.flex = flex; }, _updateGridLayout: function() { // show/hide columns let narrow = this.flex.hostElement.clientWidth < 600; this.flex.columns.forEach(col => { col.visible = col.index == 0 ? narrow : !narrow; }); // make rows taller on phone layout this.flex.rows.defaultSize = this._defaultRowHeight * (narrow ? 3 : 1); // hide column headers on narrow layouts this.flex.headersVisibility = narrow ? wjcGrid.HeadersVisibility.None : wjcGrid.HeadersVisibility.Column; } }, mounted: function() { // get some data wijmo.httpRequest( "https://services.odata.org/Northwind/Northwind.svc/Customers?$format=json", { success: xhr => { let response = JSON.parse(xhr.responseText); this.flex.itemsSource = response.value; this._updateGridLayout(); } } ); this._defaultRowHeight = this.flex.rows.defaultSize; this.flex.addEventListener( window, "resize", this._updateGridLayout.bind(this) ); } }); new Vue({ render: h => h(App) }).$mount("#app"); </script> <style> /* set grid height */ .wj-flexgrid { height: 350px; -moz-user-select: none; } /* disable alternating rows */ .wj-alt:not(.wj-header):not(.wj-group):not(.wj-state-selected):not(.wj-state-multi-selected) { background: #fff; } /* format detail cells */ .item-header { font-weight: bold; font-size: 150%; } .item-detail { margin-left: 12px; } </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/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> 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 wjcCore from '@grapecity/wijmo'; import * as wjcGrid from "@grapecity/wijmo.react.grid"; import * as wjGrid from '@grapecity/wijmo.grid'; class App extends React.Component { constructor(props) { super(props); this.state = { flex: null, _defaultRowHeight: 0 }; } componentDidMount() { wjcCore.httpRequest("https://services.odata.org/Northwind/Northwind.svc/Customers?$format=json", { success: xhr => { let response = JSON.parse(xhr.responseText); this.flex.itemsSource = response.value; this._updateGridLayout(); } }); this.setState({ _defaultRowHeight: this.flex.rows.defaultSize }); this.flex.addEventListener(window, "resize", this._updateGridLayout.bind(this)); } render() { return <div className="container-fluid"> <wjcGrid.FlexGrid headersVisibility="Column" initialized={this.initializeGrid.bind(this)}> <wjcGrid.FlexGridColumn header="Company" visible={false} width="*" isReadOnly={true} allowDragging={false}></wjcGrid.FlexGridColumn> <wjcGrid.FlexGridColumn binding="CompanyName" header="Company Name" width="20*"></wjcGrid.FlexGridColumn> <wjcGrid.FlexGridColumn binding="ContactName" header="Contact Name" width="15*"></wjcGrid.FlexGridColumn> <wjcGrid.FlexGridColumn binding="ContactTitle" header="Contact Title" width="20*"></wjcGrid.FlexGridColumn> <wjcGrid.FlexGridColumn binding="Address" header="Address" width="20*"></wjcGrid.FlexGridColumn> <wjcGrid.FlexGridColumn binding="City" header="City" width="10*"></wjcGrid.FlexGridColumn> <wjcGrid.FlexGridColumn binding="Country" header="Country" width="15*"></wjcGrid.FlexGridColumn> </wjcGrid.FlexGrid> </div>; } initializeGrid(flex) { flex.formatItem.addHandler((s, e) => { // show company summary on narrow layout if (e.panel == s.cells && e.col == 0) { let html = wjcCore.format('<div class="item-header">{CompanyName}</div>' + '<div class="item-detail">{ContactName}, {ContactTitle}</div>' + '<div class="item-detail">{Address}, {City}, {Country}</div>', s.rows[e.row].dataItem); e.cell.innerHTML = html; } }); this.flex = flex; } _updateGridLayout() { // show/hide columns let narrow = this.flex.hostElement.clientWidth < 600; this.flex.columns.forEach(col => { col.visible = col.index == 0 ? narrow : !narrow; }); // make rows taller on phone layout this.flex.rows.defaultSize = this.state._defaultRowHeight * (narrow ? 3 : 1); // hide column headers on narrow layouts this.flex.headersVisibility = narrow ? wjGrid.HeadersVisibility.None : wjGrid.HeadersVisibility.Column; } } 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> /* set grid height */ .wj-flexgrid { height: 350px; -moz-user-select: none; } /* disable alternating rows */ .wj-alt:not(.wj-header):not(.wj-group):not(.wj-state-selected):not(.wj-state-multi-selected) { background: #fff; } /* format detail cells */ .item-header { font-weight: bold; font-size: 150%; } .item-detail { margin-left: 12px; }