Server-Side Paging

Server-side paging consists of making requests that bring in one page of data at a time. The actual commands used to retrieve the data depend on the API exposed by the server. Wijmo includes an ODataCollectionView class that implements server-based paging (as well as sorting and filtering) for OData data sources.

import 'bootstrap.css'; import '@grapecity/wijmo.styles/wijmo.css'; import * as wjCore from '@grapecity/wijmo'; import * as wjGrid from '@grapecity/wijmo.grid'; import * as wjOdata from '@grapecity/wijmo.odata'; // document.readyState === 'complete' ? init() : window.onload = init; // function init() { // // use ODataCollectionView to demonstrate server-based paging var url = 'https://services.odata.org/Northwind/Northwind.svc'; var viewOd = new wjOdata.ODataCollectionView(url, 'Customers', { pageSize: 6, pageOnServer: true, sortOnServer: true, pageChanged: updateCurrentPageOd, loaded: updateCurrentPageOd }); // // update pager status viewOd.onPageChanged(); function updateCurrentPageOd() { var curr = wjCore.format('Page {index:n0} of {cnt:n0}', { index: viewOd.pageIndex + 1, cnt: viewOd.pageCount }); document.getElementById('spanCurrent').value = curr; } // // implement pager document.getElementById('pagerOd').addEventListener('click', function (e) { var btn = wjCore.closest(e.target, 'button'); var id = btn ? btn.id : ''; switch (id) { case 'btnFirstOd': viewOd.moveToFirstPage(); break; case 'btnPrevOd': viewOd.moveToPreviousPage(); break; case 'btnNextOd': viewOd.moveToNextPage(); break; case 'btnLastOd': viewOd.moveToLastPage(); break; } }); // // show the OData in a grid var flexOd = new wjGrid.FlexGrid('#theGridOd', { itemsSource: viewOd, alternatingRowStep: 0, headersVisibility: 'Column', isReadOnly: true // the Northwind sample service is read-only! }); } <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <title>GrapeCity Wijmo FlexGrid Server-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="theGridOd"> </div> <div id="pagerOd" class="wj-control wj-content wj-pager"> <div class="wj-input-group"> <span class="wj-input-group-btn"> <button id="btnFirstOd" 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="btnPrevOd" 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="btnNextOd" class="wj-btn wj-btn-default" type="button"> <span class="wj-glyph-right"></span> </button> </span> <span class="wj-input-group-btn"> <button id="btnLastOd" 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 wjcOData from '@grapecity/wijmo.odata'; 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: wjcOData.ODataCollectionView; constructor() { let url = 'https://services.odata.org/Northwind/Northwind.svc'; this.data = new wjcOData.ODataCollectionView(url, 'Customers', { pageSize: 6, pageOnServer: true, sortOnServer: true, }); } } // @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 Server-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 [isReadOnly]="true" [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 :isReadOnly=true :alternatingRowStep=0 headersVisibility="Column" :itemsSource="data" :initialized="initializeGrid"> </wj-flex-grid> <div id="pagerOd" class="wj-control wj-content wj-pager"> <div class="wj-input-group"> <span class="wj-input-group-btn"> <button id="btnFirstOd" 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="btnPrevOd" class="wj-btn wj-btn-default" type="button"> <span class="wj-glyph-left"></span> </button> </span> <input id="spanCurrentOd" class="wj-form-control" disabled type="text"> <span class="wj-input-group-btn"> <button id="btnNextOd" class="wj-btn wj-btn-default" type="button"> <span class="wj-glyph-right"></span> </button> </span> <span class="wj-input-group-btn"> <button id="btnLastOd" 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 wjOdata from '@grapecity/wijmo.odata'; 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){ var url = 'https://services.odata.org/Northwind/Northwind.svc'; var viewOd = new wjOdata.ODataCollectionView(url, 'Customers', { pageSize: 6, pageOnServer: true, sortOnServer: true, pageChanged: updateCurrentPageOd, loaded: updateCurrentPageOd }); this.data = viewOd; // update pager status viewOd.onPageChanged(); function updateCurrentPageOd() { var curr = wjCore.format('Page {index:n0} of {cnt:n0}', { index: viewOd.pageIndex + 1, cnt: viewOd.pageCount }); document.getElementById('spanCurrentOd').value = curr; } // // implement pager document.getElementById('pagerOd').addEventListener('click', function(e) { var btn = wjCore.closest(e.target, 'button'); var id = btn ? btn.id : ''; switch (id) { case 'btnFirstOd': viewOd.moveToFirstPage(); break; case 'btnPrevOd': viewOd.moveToPreviousPage(); break; case 'btnNextOd': viewOd.moveToNextPage(); break; case 'btnLastOd': viewOd.moveToLastPage(); break; } }); } } }); </script> <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <title>GrapeCity Wijmo FlexGrid Server-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 wjcCore from '@grapecity/wijmo'; import * as wjcGrid from "@grapecity/wijmo.react.grid"; import * as wjcOData from '@grapecity/wijmo.odata'; class App extends React.Component { constructor(props) { super(props); this.state = { data: null }; } render() { return <div className="container-fluid"> <wjcGrid.FlexGrid isReadOnly={true} alternatingRowStep={0} headersVisibility="Column" itemsSource={this.state.data} initialized={this.initializeGrid.bind(this)}> </wjcGrid.FlexGrid> <div id="pagerOd" className="wj-control wj-content wj-pager"> <div className="wj-input-group"> <span className="wj-input-group-btn"> <button id="btnFirstOd" 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="btnPrevOd" type="button" className="wj-btn wj-btn-default"> <span className="wj-glyph-left"></span> </button> </span> <input id="spanCurrentOd" disabled={true} type="text" className="wj-form-control"/> <span className="wj-input-group-btn"> <button id="btnNextOd" type="button" className="wj-btn wj-btn-default"> <span className="wj-glyph-right"></span> </button> </span> <span className="wj-input-group-btn"> <button id="btnLastOd" 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) { var url = 'https://services.odata.org/Northwind/Northwind.svc'; var viewOd = new wjcOData.ODataCollectionView(url, 'Customers', { pageSize: 6, pageOnServer: true, sortOnServer: true, pageChanged: updateCurrentPageOd, loaded: updateCurrentPageOd }); this.setState({ data: viewOd }); // update pager status viewOd.onPageChanged(); function updateCurrentPageOd() { var curr = wjcCore.format('Page {index:n0} of {cnt:n0}', { index: viewOd.pageIndex + 1, cnt: viewOd.pageCount }); document.getElementById('spanCurrentOd').value = curr; } // // implement pager document.getElementById('pagerOd').addEventListener('click', function (e) { var btn = wjcCore.closest(e.target, 'button'); var id = btn ? btn.id : ''; switch (id) { case 'btnFirstOd': viewOd.moveToFirstPage(); break; case 'btnPrevOd': viewOd.moveToPreviousPage(); break; case 'btnNextOd': viewOd.moveToNextPage(); break; case 'btnLastOd': viewOd.moveToLastPage(); break; } }); } _getData() { } } 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 Server-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 id="app"></div> </body> </html>