Grid with Material 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.
selectionmode property – Sets or gets the selection mode.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.pagerheight property – Sets or gets the height of the Grid Pager.width property – Sets or gets the Grid's width.columns property – Sets the Grid columns.columnsresize property – Enables or disables the columns resizing.pagermode property – Sets or gets the rendering mode of the pager.pageable property – Enables or disables the Grid Paging feature.sortable property – The sortable property enables or disables the sorting feature.source property – Sets and gets the source.pagechanged event – This event is triggered when the current page is changed.pagesizechanged event – This event is triggered when the page size is changed.getpaginginformation method – Gets the paging information.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, jqxlistbox.js, jqxdropdownlist.js, jqxmenu.js, jqxgrid.js, jqxgrid.pager.js, jqxgrid.sort.js, jqxgrid.filter.js, jqxgrid.columnsresize.js, jqxgrid.selection.js, jqxpanel.js.
It also loads helper scripts of this demo site, which are not part of the library: demos.js (getWidth() and other layout helpers).
$(document).ready(function () {
var url = "../sampledata/orders.xml";
// prepare the data
var source =
{
datatype: "xml",
datafields: [
{ name: 'ShippedDate', map: 'm\\:properties>d\\:ShippedDate', type: 'date' },
{ name: 'Freight', map: 'm\\:properties>d\\:Freight', type: 'float' },
{ name: 'ShipName', map: 'm\\:properties>d\\:ShipName' },
{ name: 'ShipAddress', map: 'm\\:properties>d\\:ShipAddress' },
{ name: 'ShipCity', map: 'm\\:properties>d\\:ShipCity' },
{ name: 'ShipCountry', map: 'm\\:properties>d\\:ShipCountry' }
],
root: "entry",
record: "content",
id: 'm\\:properties>d\\:OrderID',
url: url,
pager: function (pagenum, pagesize, oldpagenum) {
// callback called when a page or page size is changed.
}
};
var dataAdapter = new $.jqx.dataAdapter(source);
$("#grid").jqxGrid(
{
width: getWidth('Grid'),
source: dataAdapter,
selectionmode: 'multiplerowsextended',
sortable: true,
pageable: true,
pagermode: 'material',
pagerheight: 50,
autoheight: true,
columnsresize: true,
columns: [
{ text: 'Ship Name', datafield: 'ShipName', width: 250 },
{ text: 'Shipped Date', datafield: 'ShippedDate', width: 230, cellsformat: 'D' },
{ text: 'Freight', datafield: 'Freight', width: 130, cellsformat: 'F2', cellsalign: 'right' },
{ text: 'Ship Address', datafield: 'ShipAddress', width: 350 },
{ text: 'Ship City', datafield: 'ShipCity', width: 100 },
{ text: 'Ship Country', datafield: 'ShipCountry', width: 101 }
]
});
$('#events').jqxPanel({ width: 300, height: 300});
$("#grid").on("pagechanged", function (event) {
$("#eventslog").css('display', 'block');
if ($("#events").find('.logged').length >= 5) {
$("#events").jqxPanel('clearcontent');
}
var args = event.args;
var eventData = "pagechanged <div>Page:" + args.pagenum + ", Page Size: " + args.pagesize + "</div>";
$('#events').jqxPanel('prepend', '<div class="logged" style="margin-top: 5px;">' + eventData + '</div>');
// get page information.
var paginginformation = $("#grid").jqxGrid('getpaginginformation');
$('#paginginfo').html("<div style='margin-top: 5px;'>Page:" + paginginformation.pagenum + ", Page Size: " + paginginformation.pagesize + ", Pages Count: " + paginginformation.pagescount + "</div>");
});
$("#grid").on("pagesizechanged", function (event) {
$("#eventslog").css('display', 'block');
$("#events").jqxPanel('clearcontent');
var args = event.args;
var eventData = "pagesizechanged <div>Page:" + args.pagenum + ", Page Size: " + args.pagesize + ", Old Page Size: " + args.oldpagesize + "</div>";
$('#events').jqxPanel('prepend', '<div style="margin-top: 5px;">' + eventData + '</div>');
// get page information.
var paginginformation = $("#grid").jqxGrid('getpaginginformation');
$('#paginginfo').html("<div style='margin-top: 5px;'>Page:" + paginginformation.pagenum + ", Page Size: " + paginginformation.pagesize + ", Pages Count: " + paginginformation.pagescount + "</div>");
});
});
<div id="jqxWidget" style="font-size: 13px; font-family: Verdana;">
<div id="grid">
</div>
<div id="eventslog" style="display: none; margin-top: 30px;">
<div style="float: left;">
Event Log:
<div style="border: none;" id="events">
</div>
</div>
<div style="float: left;">
Paging Details:
<div id="paginginfo">
</div>
</div>
</div>
</div>