Row grouping is a premium feature which allows plugin users to group row data.
Inline demo server-side row grouping #
Product line | Product ID | Product name | Vendor | Stock | Price | Retail price | Description |
---|---|---|---|---|---|---|---|
Product line | Product ID | Product name | Vendor | Stock | Price | Retail price | Description |
Enable row grouping #
With WP Data Access premium installed option rowGroup is available from advanced table options which adds row grouping to a data table. Additional row grouping options…
The endRender function of the example above calls javascript function code_manager_row_grouping_demo. This function needs to be added to the page using a plugin like the Code Manager.
Advanced options to add row grouping
{
"rowGroup": {
"dataSrc": 0,
"endRender": "function ( rows, group ) { return code_manager_row_grouping_demo(rows, group) }"
}
}
Advanced options to add row grouping
function code_manager_row_grouping_demo(rows, group) {
var avgInStock = rows.data().pluck(4).reduce( function (a, b) { return parseFloat(a) + parseFloat(b); } ) / rows.count();
var avgPrice = rows.data().pluck(5).reduce( function (a, b) { return parseFloat(a) + parseFloat(b); } ) / rows.count();
avgPrice = jQuery.fn.dataTable.render.number('.', ',', 2, '$').display( avgPrice );
var avgRetailPrice = rows.data().pluck(6).reduce( function (a, b) { return parseFloat(a) + parseFloat(b); } ) / rows.count();
avgRetailPrice = jQuery.fn.dataTable.render.number('.', ',', 2, '$').display( avgRetailPrice );
//return "Average for " + group + ": " + Math.floor(avgInStock) + " : " + avgPrice + " : " + avgRetailPrice;
return jQuery('<tr/>')
.append('<td colspan="4">Averages for '+group+'</td>' )
.append('<td class="quantityInStock">'+Math.floor(avgInStock)+'</td>')
.append('<td class="buyPrice">'+avgPrice+'</td>')
.append('<td class="MSRP">'+avgRetailPrice+'</td>');
}
Limitations #
Inline demo client-side row grouping #
Product line | Product ID | Product name | Vendor | Stock | Price | Retail price | Description |
---|---|---|---|---|---|---|---|
Product line | Product ID | Product name | Vendor | Stock | Price | Retail price | Description |