Index

  1. Home
  2. Docs
  3. Index
  4. Data Publisher
  5. Row grouping

Row grouping

Row grouping is a premium feature which allows plugin users to group row data.

Enable row grouping

{
	"rowGroup": { 
		"dataSrc": 0,
		"endRender": "function ( rows, group ) { return code_manager_row_grouping_demo(rows, group) }"
	}
}

With WP Data Access premium installed option rowGroup is available from advanced table options which adds row grouping to a publication. Additional row grouping options…

The endRender function of this rowGroup calls javascript function code_manager_row_grouping_demo. This function was added to this page with the Code Manager.

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

  • Column ordering cannot be changed interactively with server-side processing (only supported with client-side processing)
  • Nested grouping is not supported
  • Grouping information is not exported (PDF, CSV, etc)
Was this article helpful to you? Yes No

Leave a Reply

Your email address will not be published. Required fields are marked *

4 − three =