Angular UI Components Documentation
Grid Paging
jqxGrid component has a built-in paging capability that supports paging functionality. The paging functionality is enabled when the 'pageable' property is set to true. The code example below illustrates how to enable the paging functionality.<jqxGrid (onPagechanged)="onPageChanged($event)" (onPagesizechanged)="onPageSizeChanged($event)" [width]="width" [source]="source" [columns]="columns" [pageable]="true"></jqxGrid>
When a page is changed or the page size is changed, the Grid raises the pagechanged or pagesizechanged events.
onPageChanged(event: any): void { let args = event.args; let pagenumber = args.pagenum; let pagesize = args.pagesize;},onPageSizeChanged(event: any): void { let args = event.args; let pagenumber = args.pagenum; let pagesize = args.pagesize;}
Grid with Basic Paging
app.component.html
<jqxGrid [theme]="'material'" [width]="'100%'" [source]="dataAdapter" [columns]="columns" [autoheight]="true" [pageable]="true"></jqxGrid>
app.component.ts
import { Component } from '@angular/core';@Component({ selector: 'app-root', templateUrl: './app.component.html'})export class AppComponent { source: any = { localdata: [ ['Alfreds Futterkiste', 'Maria Anders', 'Berlin', 'Germany'], ['Ana Trujillo Emparedados y helados', 'Ana Trujillo', 'Mxico D.F.', 'Mexico'], ['Antonio Moreno Taquera', 'Antonio Moreno', 'Mxico D.F.', 'Mexico'], ['Around the Horn', 'Thomas Hardy', 'London', 'UK'], ['Berglunds snabbkp', 'Christina Berglund', 'Lule', 'Sweden'], ['Blauer See Delikatessen', 'Hanna Moos', 'Mannheim', 'Germany'], ['Blondesddsl pre et fils', 'Frdrique Citeaux', 'Strasbourg', 'France'], ['Blido Comidas preparadas', 'Martn Sommer', 'Madrid', 'Spain'], ['Bon app', 'Laurence Lebihan', 'Marseille', 'France'], ['Bottom-Dollar Markets', 'Elizabeth Lincoln', 'Tsawassen', 'Canada'], ['B`s Beverages', 'Victoria Ashworth', 'London', 'UK'], ['Cactus Comidas para llelet', 'Patricio Simpson', 'Buenos Aires', 'Argentina'], ['Centro comercial Moctezuma', 'Francisco Chang', 'Mxico D.F.', 'Mexico'], ['Chop-suey Chinese', 'Yang Wang', 'Bern', 'Switzerland'], ['Comrcio Mineiro', 'Pedro Afonso', 'Sao Paulo', 'Brazil'], ['Consolidated Holdings', 'Elizabeth Brown', 'London', 'UK'], ['Drachenblut Delikatessen', 'Sven Ottlieb', 'Aachen', 'Germany'], ['Du monde entier', 'Janine Labrune', 'Nantes', 'France'], ['Eastern Connection', 'Ann Devon', 'London', 'UK'], ['Ernst Handel', 'Roland Mendel', 'Graz', 'Austria'] ], datafields: [ { name: 'ContactName', type: 'string', map: '0' }, { name: 'Title', type: 'string', map: '1' }, { name: 'City', type: 'string', map: '2' }, { name: 'Country', type: 'string', map: '3' } ], datatype: 'array' }; dataAdapter: any = new jqx.dataAdapter(this.source); columns: any[] = [ { text: 'Contact Name', datafield: 'ContactName' }, { text: 'Contact Title', datafield: 'Title' }, { text: 'City', datafield: 'City' }, { text: 'Country', datafield: 'Country' } ];}
The Grid Page Size options are displayed in a DropDownList component in the pager area. By default, the size options are 5, 10 and 20. The "pagesizeoptions" property enables you to set new size options.
<jqxGrid [width]="width" [source]="source" [columns]="columns" [pageable]="true" [pagesizeoptions]="['10', '20', '30']"></jqxGrid>
The 'pagesize' property sets the default page size when the paging functionality is enabled. By default the Grid displays 10 rows in a page.
The 'pagerrenderer' property allows you to customize the UI of the Grid pager. In the sample below, we create a pagerrenderer function and inside the function, we build a DIV element with anchor tags. Each anchor tag has a page number as text. When the user clicks an anchor tag, the Grid calls the 'gotopage' function to navigate to a page. The 'pagerrenderer' function returns the DIV element as a result. This element is then internally appended to the Grid's pager area.
Grid with Custom Paging
app.component.html
<jqxGrid #myGrid [theme]="'material'" [width]="'100%'" [source]="dataAdapter" [columns]="columns" [autoheight]="true" [pageable]="true" [pagerrenderer]="pagerrenderer"></jqxGrid>
app.component.ts
import { Component, ViewChild } from '@angular/core';import { jqxGridComponent } from 'jqwidgets-scripts/jqwidgets-ts/angular_jqxgrid';declare var $;@Component({ selector: 'app-root', templateUrl: './app.component.html'})export class AppComponent { @ViewChild('myGrid') myGrid: jqxGridComponent; source: any = { localdata: [ ['Alfreds Futterkiste', 'Maria Anders', 'Berlin', 'Germany'], ['Ana Trujillo Emparedados y helados', 'Ana Trujillo', 'Mxico D.F.', 'Mexico'], ['Antonio Moreno Taquera', 'Antonio Moreno', 'Mxico D.F.', 'Mexico'], ['Around the Horn', 'Thomas Hardy', 'London', 'UK'], ['Berglunds snabbkp', 'Christina Berglund', 'Lule', 'Sweden'], ['Blauer See Delikatessen', 'Hanna Moos', 'Mannheim', 'Germany'], ['Blondesddsl pre et fils', 'Frdrique Citeaux', 'Strasbourg', 'France'], ['Blido Comidas preparadas', 'Martn Sommer', 'Madrid', 'Spain'], ['Bon app', 'Laurence Lebihan', 'Marseille', 'France'], ['Bottom-Dollar Markets', 'Elizabeth Lincoln', 'Tsawassen', 'Canada'], ['B`s Beverages', 'Victoria Ashworth', 'London', 'UK'], ['Cactus Comidas para llelet', 'Patricio Simpson', 'Buenos Aires', 'Argentina'], ['Centro comercial Moctezuma', 'Francisco Chang', 'Mxico D.F.', 'Mexico'], ['Chop-suey Chinese', 'Yang Wang', 'Bern', 'Switzerland'], ['Comrcio Mineiro', 'Pedro Afonso', 'Sao Paulo', 'Brazil'], ['Consolidated Holdings', 'Elizabeth Brown', 'London', 'UK'], ['Drachenblut Delikatessen', 'Sven Ottlieb', 'Aachen', 'Germany'], ['Du monde entier', 'Janine Labrune', 'Nantes', 'France'], ['Eastern Connection', 'Ann Devon', 'London', 'UK'], ['Ernst Handel', 'Roland Mendel', 'Graz', 'Austria'] ], datafields: [ { name: 'ContactName', type: 'string', map: '0' }, { name: 'Title', type: 'string', map: '1' }, { name: 'City', type: 'string', map: '2' }, { name: 'Country', type: 'string', map: '3' } ], datatype: 'array' }; dataAdapter: any = new jqx.dataAdapter(this.source); columns: any[] = [ { text: 'Contact Name', datafield: 'ContactName' }, { text: 'Contact Title', datafield: 'Title' }, { text: 'City', datafield: 'City' }, { text: 'Country', datafield: 'Country' } ]; pagerrenderer = () => { let element = $("<div style='margin-top: 5px; width: 100%; height: 100%;'></div>"); let paginginfo = this.myGrid.getpaginginformation(); for (i = 0; i < paginginfo.pagescount; i++) { // add anchor tag with the page number for each page. let anchor = $("<a style='padding: 5px; color: blue;'>" + i + "</a>"); anchor.appendTo(element); anchor.click((event) => { // go to a page. let pagenum = parseInt($(event.target).text()); this.myGrid.gotopage(pagenum); }); } return element; }}
To navigate to a page with the Grid API, use the 'gotopage' function.
this.myGrid.gotopage(1);
The 'gotoprevpage' function navigates with 1 page before the current page.
The 'gotonextpage' function navigates with 1 page after the current page.