Customize the rendering of the jqxGrid's Pager.
A live JavaScript/jQuery example of jqxGrid, the jQWidgets Grid component, with its complete source code below. It is one of 139 jqxGrid demos for jQuery.
pagerrenderer property – The function is called when the Grid Pager is rendered.theme property – Sets the widget's theme.autoheight property – Sets or gets the height of the grid to be equal to the summary height of the grid rows.height property – Sets or gets the Grid's height.width property – Sets or gets the Grid's width.columns property – Sets the Grid columns.columnsresize property – Enables or disables the columns resizing.pageable property – Enables or disables the Grid Paging feature.source property – Sets and gets the source.pagechanged event – This event is triggered when the current page is changed.getdatainformation method – Gets bound data information.gotoprevpage method – Navigates to a previous page when the Grid paging is enabled i.e when the pageable property value is true.gotonextpage method – Navigates to a next page when the Grid paging is enabled i.e when the pageable property value is true.To run it in your own page, load jqx.base.css, a theme and the library files below from npm (npm install jqwidgets-scripts) or the jsDelivr CDN, then add the markup and the script. jQuery is not required: jqxcore.js provides $. Getting started with jqxGrid shows the setup step by step.
The page loads jqx.base.css, a theme and these library files: jqxcore.js, jqxdata.js, jqxbuttons.js, jqxscrollbar.js, jqxmenu.js, jqxgrid.js, jqxgrid.selection.js, jqxgrid.columnsresize.js, jqxlistbox.js, jqxgrid.pager.js, jqxdropdownlist.js.
It also loads helper scripts of this demo site, which are not part of the library: demos.js (getWidth() and other layout helpers), generatedata.js (generatedata(), random sample rows).
$(document).ready(function () {
var source =
{
localdata: generatedata(55),
datafields:
[
{ name: 'firstname', type: 'string' },
{ name: 'lastname', type: 'string' },
{ name: 'productname', type: 'string' },
{ name: 'quantity', type: 'number' },
{ name: 'price', type: 'number' },
{ name: 'total', type: 'number' }
],
datatype: "array"
};
var dataAdapter = new $.jqx.dataAdapter(source);
var self = this;
var pagerrenderer = function () {
var element = $("<div style='margin-left: 10px; margin-top: 11px; width: 100%; height: 100%;'></div>");
var datainfo = $("#grid").jqxGrid('getdatainformation');
var paginginfo = datainfo.paginginformation;
var leftButton = $("<div style='padding: 0px; float: left;'><div style='margin-left: 9px; width: 16px; height: 16px;'></div></div>");
leftButton.find('div').addClass('jqx-icon-arrow-left');
leftButton.width(36);
// leftButton.jqxButton({ theme: theme });
var rightButton = $("<div style='padding: 0px; margin: 0px 3px; float: left;'><div style='margin-left: 9px; width: 16px; height: 16px;'></div></div>");
rightButton.find('div').addClass('jqx-icon-arrow-right');
rightButton.width(36);
// rightButton.jqxButton({ theme: theme });
leftButton.appendTo(element);
rightButton.appendTo(element);
var label = $("<div style='font-size: 11px; margin: 2px 3px; margin-top:-5px; font-weight: bold; float: left;'></div>");
label.text("1-" + paginginfo.pagesize + ' of ' + datainfo.rowscount);
label.appendTo(element);
self.label = label;
// update buttons states.
var handleStates = function (event, button, className, add) {
button.on(event, function () {
if (add == true) {
button.find('div').addClass(className);
}
else button.find('div').removeClass(className);
});
}
if (theme != '') {
handleStates('mousedown', rightButton, 'jqx-icon-arrow-right-selected-' + theme, true);
handleStates('mouseup', rightButton, 'jqx-icon-arrow-right-selected-' + theme, false);
handleStates('mousedown', leftButton, 'jqx-icon-arrow-left-selected-' + theme, true);
handleStates('mouseup', leftButton, 'jqx-icon-arrow-left-selected-' + theme, false);
handleStates('mouseenter', rightButton, 'jqx-icon-arrow-right-hover-' + theme, true);
handleStates('mouseleave', rightButton, 'jqx-icon-arrow-right-hover-' + theme, false);
handleStates('mouseenter', leftButton, 'jqx-icon-arrow-left-hover-' + theme, true);
handleStates('mouseleave', leftButton, 'jqx-icon-arrow-left-hover-' + theme, false);
}
rightButton.click(function () {
$("#grid").jqxGrid('gotonextpage');
});
leftButton.click(function () {
$("#grid").jqxGrid('gotoprevpage');
});
return element;
}
$("#grid").on('pagechanged', function () {
var datainfo = $("#grid").jqxGrid('getdatainformation');
var paginginfo = datainfo.paginginformation;
self.label.text(1 + paginginfo.pagenum * paginginfo.pagesize + "-" + Math.min(datainfo.rowscount, (paginginfo.pagenum + 1) * paginginfo.pagesize) + ' of ' + datainfo.rowscount);
});
$("#grid").jqxGrid(
{
source: dataAdapter,
columnsresize: true,
width: getWidth('Grid'),
pageable: true,
autoheight: true,
pagerrenderer: pagerrenderer,
columns: [
{ text: 'First Name', dataField: 'firstname', width: 200 },
{ text: 'Last Name', dataField: 'lastname', width: 200 },
{ text: 'Product', dataField: 'productname', width: 170 },
{ text: 'Quantity', dataField: 'quantity', width: 80, cellsalign: 'right' },
{ text: 'Unit Price', dataField: 'price', width: 90, cellsalign: 'right', cellsformat: 'c2' },
{ text: 'Total', dataField: 'total', cellsalign: 'right', cellsformat: 'c2' }
]
});
});
<div id="jqxWidget">
<div id="grid"></div>
</div>