Quantcast
Channel: Recent Discussions — DataTables forums
Viewing all articles
Browse latest Browse all 82121

Grouping on 2 two levels with total

$
0
0
Hi everybody,

I try to create a table with two levels of grouping and a total by column.

I have created the two levels grouping by using this code :

"fnDrawCallback": function ( oSettings ) {
	if ( oSettings.aiDisplay.length == 0 )
	{
		return;
	}
	 
	var nTrs = jQuery(' tbody tr');
	var sLastGroup = "";
	var sLastGroup2 = "";
	var sLastGroup2 = "";
	
	for ( var i=0 ; i<nTrs.length ; i++ )
	{
		var iDisplayIndex = oSettings._iDisplayStart + i;
		var sGroup = oSettings.aoData[ oSettings.aiDisplay[iDisplayIndex] ]._aData[0];
		if ( sGroup != sLastGroup )
		{
			var nGroup = document.createElement( 'tr' );
			var nCell = document.createElement( 'td' );
			nCell.className = "group";
			nCell.innerHTML = sGroup;
			nGroup.appendChild( nCell );
			nTrs[i].parentNode.insertBefore( nGroup, nTrs[i] );
			sLastGroup = sGroup;
		}
	}

	for ( var i=0 ; i<nTrs.length ; i++ )
	{
		var iDisplayIndex = oSettings._iDisplayStart + i;
		var sGroup2 = oSettings.aoData[ oSettings.aiDisplay[iDisplayIndex] ]._aData[1];
		if ( sGroup2 != sLastGroup2 )
		{
			var nGroup = document.createElement( 'tr' );
			var nCell = document.createElement( 'td' );
			nCell.className = "subgroup";
			nCell.innerHTML = sGroup2;
			nGroup.appendChild( nCell );
			nTrs[i].parentNode.insertBefore( nGroup, nTrs[i] );
			sLastGroup2 = sGroup2;
		}
	}
}

The example with one level grouping is here : http://www.datatables.net/release-datatables/examples/advanced_init/row_grouping.html
Imagine we have two more columns in the online example : amount and tax
I would like to add a total cell for these two news columns.
And if it's possible, display these total cell in the grouping cell (I don't want to merge the td, so I don't use colspan because I would like to write total in td of grouping cell) => After "Gecko, KHTML, Misc, Presto, etc." if we keep the online example.


Thanks in advance for your help.

Viewing all articles
Browse latest Browse all 82121

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>