Quantcast
Channel: DataTables 1.9 — DataTables forums
Viewing all articles
Browse latest Browse all 1817

Paging with Row Grouping

$
0
0
Hi, I've followed this example to add grouping rows to my table:

http://datatables.net/release-datatables/examples/advanced_init/row_grouping.html

It works well, but when you apply paging, it displays iDisplayLength number of rows plus the added grouping rows.

What's the best way to make it show iDisplayLength number of rows including the grouping rows?

Apologies if it's a stupid question, this is my first foray into the world of JQuery.

Any help would be appreciated.

$('#new_1').dataTable({
    "fnDrawCallback": function ( oSettings ) {
        if ( oSettings.aiDisplay.length == 0 )
        {
	return;
        }
						
        var nTrs = $('tbody tr', oSettings.nTable);
        var iColspan = nTrs[0].getElementsByTagName('td').length;
        var sLastGroup = "";
        var sLastGroup1 = "";
	
        for ( var i=0 ; i<nTrs.length ; i++ )
        {
	var iDisplayIndex = oSettings._iDisplayStart + i;
	var sGroup = oSettings.aoData[ oSettings.aiDisplay[iDisplayIndex] ]._aData[0];
	var sGroup1 = oSettings.aoData[ oSettings.aiDisplay[iDisplayIndex] ]._aData[1];
	
                if ( sGroup != sLastGroup )
	{
	        var nGroup = document.createElement( 'tr' );
	        var nCell = document.createElement( 'td' );
	        nCell.colSpan = iColspan;
	        nCell.className = "group";
	        nCell.innerHTML = sGroup;
	        nGroup.appendChild( nCell );
	        nTrs[i].parentNode.insertBefore( nGroup, nTrs[i] );
                        sLastGroup = sGroup;
	        sLastGroup1 = "";
	        pageDisplay--;
	}
                				
	if ( sGroup1 != sLastGroup1 )
	{
	        var nGroup = document.createElement( 'tr' );
	        var nCell = document.createElement( 'td' );
	        nCell.colSpan = iColspan;
	        nCell.className = "group";
	        nCell.innerHTML = sGroup1;
	        nGroup.appendChild( nCell );
	        nTrs[i].parentNode.insertBefore( nGroup, nTrs[i] );
	        sLastGroup1 = sGroup1;
	        pageDisplay--;
	}
        }
    },
    "aLengthMenu": [
            [5, 15, 20, -1],
            [5, 15, 20, "All"] // change per page values here
    ],
    "iDisplayLength": pageDisplay,
    "sDom": "<'row-fluid'<'span6'l><'span6'f>r>t<'row-fluid'<'span6'i><'span6'p>>",
    "sPaginationType": "bootstrap",
    "oLanguage": {
            "sLengthMenu": "_MENU_ records per page",
            "oPaginate": {
                    "sPrevious": "Prev",
                    "sNext": "Next"
            }
    },
    "aoColumnDefs": [
	{ "bVisible": false, "aTargets": [ 0 ] },
	{ "bVisible": false, "aTargets": [ 1 ] }
    ],
    "aaSortingFixed": [[ 0, 'asc' ], [ 1, 'asc' ]],
    "aaSorting": [[ 2, 'asc' ]]
});

Viewing all articles
Browse latest Browse all 1817

Trending Articles