浏览器端分页

分页是处理大量数据的常用技术。

客户端分页

CollectionView 类默认支持客户端分页,因此您可以生成仅包含合理数据量的网格和表。 要启用分页,请设置 pageSize 属性并使用 moveToPage 方法选择要显示的页面。

import 'bootstrap.css'; import '@grapecity/wijmo.styles/wijmo.css'; import * as wjCore from '@grapecity/wijmo'; import * as wjGrid from '@grapecity/wijmo.grid'; // document.readyState === 'complete' ? init() : window.onload = init; // function init() { // // create some random data var countries = 'US,Germany,UK,Japan,Italy,Greece'.split(','); var products = 'Piano,Violin,Flute,Guitar,Cello'.split(','); var data = []; for (var i = 0; i < 10000; i++) { data.push({ id: i, country: countries[i % countries.length], product: products[i % products.length], sales: Math.random() * 10000, expenses: Math.random() * 5000 }); } // // create a CollectionView with 20 items per page var view = new wjCore.CollectionView(data, { pageSize: 6, pageChanged: updateCurrentPage }); // // update pager status view.onPageChanged(); function updateCurrentPage() { var curr = wjCore.format('Page {index:n0} of {cnt:n0}', { index: view.pageIndex + 1, cnt: view.pageCount }); document.getElementById('spanCurrent').value = curr; } // // implement pager document.getElementById('pager').addEventListener('click', function (e) { var btn = wjCore.closest(e.target, 'button'); var id = btn ? btn.id : ''; switch (id) { case 'btnFirst': view.moveToFirstPage(); break; case 'btnPrev': view.moveToPreviousPage(); break; case 'btnNext': view.moveToNextPage(); break; case 'btnLast': view.moveToLastPage(); break; } }); // // show the data in a grid var flex = new wjGrid.FlexGrid('#theGrid', { itemsSource: view, alternatingRowStep: 0, headersVisibility: 'Column' }); } <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <title>GrapeCity Wijmo FlexGrid Client-side Paging</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 id="pager" class="wj-control wj-content wj-pager"> <div class="wj-input-group"> <span class="wj-input-group-btn"> <button id="btnFirst" class="wj-btn wj-btn-default" type="button"> <span class="wj-glyph-left" style="margin-right: -4px;"></span> <span class="wj-glyph-left"></span> </button> </span> <span class="wj-input-group-btn"> <button id="btnPrev" class="wj-btn wj-btn-default" type="button"> <span class="wj-glyph-left"></span> </button> </span> <input id="spanCurrent" class="wj-form-control" disabled type="text"> <span class="wj-input-group-btn"> <button id="btnNext" class="wj-btn wj-btn-default" type="button"> <span class="wj-glyph-right"></span> </button> </span> <span class="wj-input-group-btn"> <button id="btnLast" class="wj-btn wj-btn-default" type="button"> <span class="wj-glyph-right"></span> <span class="wj-glyph-right" style="margin-left: -4px;"></span> </button> </span> </div> </div> </div> </body> </html> import 'bootstrap.css'; import '@grapecity/wijmo.styles/wijmo.css'; // import { Component, enableProdMode, NgModule } from '@angular/core'; import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; import { BrowserModule } from '@angular/platform-browser'; import * as wjcCore from '@grapecity/wijmo'; import { WjGridModule } from '@grapecity/wijmo.angular2.grid'; import { WjInputModule } from '@grapecity/wijmo.angular2.input'; // @Component({ selector: 'app-component', templateUrl: 'src/app.component.html' }) export class AppComponent { data: wjcCore.CollectionView; constructor() { this.data = this._getData(); } private _getData() { let countries = 'US,Germany,UK,Japan,Italy,Greece'.split(','); let products = 'Piano,Violin,Flute,Guitar,Cello'.split(','); let data = []; for (let i = 0; i < 10000; i++) { data.push({ id: i, country: countries[i % countries.length], product: products[i % products.length], sales: Math.random() * 10000, expenses: Math.random() * 5000 }); } // create a CollectionView with 20 items per page let view = new wjcCore.CollectionView(data, { pageSize: 6 }); // done return view; } } // @NgModule({ imports: [WjGridModule, WjInputModule, 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 Client-side Paging</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 [alternatingRowStep]="0" [headersVisibility]="'Column'" [(itemsSource)]="data"> </wj-flex-grid> <wj-collection-view-pager [cv]="flex.collectionView"> </wj-collection-view-pager> </div> <template> <div class="container-fluid"> <wj-flex-grid :alternatingRowStep="0" headersVisibility="Column" :itemsSource="data" :initialized="initializeGrid"> </wj-flex-grid> <div id="pager" class="wj-control wj-content wj-pager"> <div class="wj-input-group"> <span class="wj-input-group-btn"> <button id="btnFirst" class="wj-btn wj-btn-default" type="button"> <span class="wj-glyph-left" style="margin-right: -4px;"></span> <span class="wj-glyph-left"></span> </button> </span> <span class="wj-input-group-btn"> <button id="btnPrev" class="wj-btn wj-btn-default" type="button"> <span class="wj-glyph-left"></span> </button> </span> <input id="spanCurrent" class="wj-form-control" disabled type="text"> <span class="wj-input-group-btn"> <button id="btnNext" class="wj-btn wj-btn-default" type="button"> <span class="wj-glyph-right"></span> </button> </span> <span class="wj-input-group-btn"> <button id="btnLast" class="wj-btn wj-btn-default" type="button"> <span class="wj-glyph-right"></span> <span class="wj-glyph-right" style="margin-left: -4px;"></span> </button> </span> </div> </div> </div> </template> <script> import "@grapecity/wijmo.styles/wijmo.css"; import "bootstrap.css"; import Vue from "vue"; import * as wjCore from '@grapecity/wijmo'; import '@grapecity/wijmo.vue2.grid'; import '@grapecity/wijmo.vue2.input'; new Vue({ el: "#app", data: { data: null }, methods:{ initializeGrid(flex){ this.data = this._getData(); }, _getData() { let countries = 'US,Germany,UK,Japan,Italy,Greece'.split(','); let products = 'Piano,Violin,Flute,Guitar,Cello'.split(','); let data = []; for (let i = 0; i < 10000; i++) { data.push({ id: i, country: countries[i % countries.length], product: products[i % products.length], sales: Math.random() * 10000, expenses: Math.random() * 5000 }); } // create a CollectionView with 20 items per page let view = new wjCore.CollectionView(data, { pageSize: 6, pageChanged: updateCurrentPage }); // // update pager status view.onPageChanged(); function updateCurrentPage() { var curr = wjCore.format('Page {index:n0} of {cnt:n0}', { index: view.pageIndex + 1, cnt: view.pageCount }); document.getElementById('spanCurrent').value = curr; } document.getElementById('pager').addEventListener('click', function(e) { var btn = wjCore.closest(e.target, 'button'); var id = btn ? btn.id : ''; switch (id) { case 'btnFirst': view.moveToFirstPage(); break; case 'btnPrev': view.moveToPreviousPage(); break; case 'btnNext': view.moveToNextPage(); break; case 'btnLast': view.moveToLastPage(); break; } }); // done return view; } } }); </script> <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <title>GrapeCity Wijmo FlexGrid Client-side Paging</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 "@grapecity/wijmo.styles/wijmo.css"; import "bootstrap.css"; // import * as React from 'react'; import * as ReactDOM from 'react-dom'; // import * as wjCore from "@grapecity/wijmo"; import * as wjcGrid from "@grapecity/wijmo.react.grid"; class App extends React.Component { constructor(props) { super(props); this.state = { data: null }; } componentDidMount() { this.setState({ data: this._getData() }); } render() { return <div className="container-fluid"> <wjcGrid.FlexGrid alternatingRowStep={0} headersVisibility="Column" itemsSource={this.state.data} initialized={this.initializeGrid.bind(this)}></wjcGrid.FlexGrid> <div id="pager" className="wj-control wj-content wj-pager"> <div className="wj-input-group"> <span className="wj-input-group-btn"> <button id="btnFirst" type="button" className="wj-btn wj-btn-default"> <span className="wj-glyph-left"></span> <span className="wj-glyph-left"></span> </button> </span> <span className="wj-input-group-btn"> <button id="btnPrev" type="button" className="wj-btn wj-btn-default"> <span className="wj-glyph-left"></span> </button> </span> <input id="spanCurrent" disabled={true} type="text" className="wj-form-control"/> <span className="wj-input-group-btn"> <button id="btnNext" type="button" className="wj-btn wj-btn-default"> <span className="wj-glyph-right"></span> </button> </span> <span className="wj-input-group-btn"> <button id="btnLast" type="button" className="wj-btn wj-btn-default"> <span className="wj-glyph-right"></span> <span className="wj-glyph-right"></span> </button> </span> </div> </div> </div>; } initializeGrid(flex) { this.data = this._getData(); } _getData() { let countries = 'US,Germany,UK,Japan,Italy,Greece'.split(','); let products = 'Piano,Violin,Flute,Guitar,Cello'.split(','); let data = []; for (let i = 0; i < 10000; i++) { data.push({ id: i, country: countries[i % countries.length], product: products[i % products.length], sales: Math.random() * 10000, expenses: Math.random() * 5000 }); } // create a CollectionView with 20 items per page let view = new wjCore.CollectionView(data, { pageSize: 6, pageChanged: updateCurrentPage }); // // update pager status view.onPageChanged(); function updateCurrentPage() { var curr = wjCore.format('Page {index: n0} of {cnt: n0}', { index: view.pageIndex + 1, cnt: view.pageCount }); document.getElementById('spanCurrent').value = curr; } document.getElementById('pager').addEventListener('click', function (e) { var btn = wjCore.closest(e.target, 'button'); var id = btn ? btn.id : ''; switch (id) { case 'btnFirst': view.moveToFirstPage(); break; case 'btnPrev': view.moveToPreviousPage(); break; case 'btnNext': view.moveToNextPage(); break; case 'btnLast': view.moveToLastPage(); break; } }); // done return view; } } 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>