Display custom aggregates in jqxGrid.
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.
altrows property – Enables or disables the alternating rows.showaggregates property – Shows or hides the aggregates in the grid's statusbar.showstatusbar property – Shows or hides the grid's statusbar.statusbarheight property – Sets the statusbar's height.width property – Sets or gets the Grid's width.columns property – Sets the Grid columns.source property – Sets and gets the source.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.aggregates.js, jqxcheckbox.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 () {
// prepare the data
var data = generatedata(200);
var source =
{
localdata: data,
datatype: "array",
datafields:
[
{ name: 'firstname', type: 'string' },
{ name: 'lastname', type: 'string' },
{ name: 'productname', type: 'string' },
{ name: 'quantity', type: 'number' },
{ name: 'price', type: 'number' }
],
updaterow: function (rowid, rowdata, commit) {
// synchronize with the server - send update command
commit(true);
}
};
var dataAdapter = new $.jqx.dataAdapter(source);
// initialize jqxGrid
$("#grid").jqxGrid(
{
width: getWidth('Grid'),
source: dataAdapter,
showstatusbar: true,
statusbarheight: 25,
altrows: true,
showaggregates: true,
columns: [
{ text: 'First Name', columntype: 'textbox', datafield: 'firstname', width: 150 },
{ text: 'Last Name', datafield: 'lastname', columntype: 'textbox', width: 150 },
{ text: 'Product', datafield: 'productname', width: 200 },
{ text: 'Quantity', datafield: 'quantity', width: 100, cellsalign: 'right', cellsformat: 'n2' },
{ text: 'Price', datafield: 'price', cellsalign: 'right', cellsformat: 'c2', aggregates: [{ '<b>Total</b>':
function (aggregatedValue, currentValue, column, record) {
var total = currentValue * parseInt(record['quantity']);
return aggregatedValue + total;
}
}]
}
]
});
});
<div id="jqxWidget">
<div id="grid"></div>
</div>