DataTables server-side processing with user selectable rows example

Preamble

When you want to detail with user selectable rows and DataTables, it is relatively simple when using DOM based data - but if using server-side processing, DataTables doesn't retain state over pages / filters etc, leaving this to the server-side instead. As such, you will need to keep a track of which rows a user as selected and mark them as selected on each draw. This is shown in this demo, which uses a unique ID assigned to the TR element (this is done automatically through the use of the DT_RowId special property returned as part of the object given by the server for each row).

Live example

Rendering engine Browser Platform(s) Engine version CSS grade
Loading data from server
Rendering engine Browser Platform(s) Engine version CSS grade

Initialisation code

$(document).ready(function() {
	var aSelected = [];
	
	/* Init the table */
	$("#example").dataTable({
		"bProcessing": true,
		"bServerSide": true,
		"sAjaxSource": "scripts/id.php",
		"fnRowCallback": function( nRow, aData, iDisplayIndex ) {
			if ( jQuery.inArray(aData.DT_RowId, aSelected) !== -1 ) {
				$(nRow).addClass('row_selected');
			}
		}
	});
	
	/* Click event handler */
	$('#example tbody tr').live('click', function () {
		var id = this.id;
		var index = jQuery.inArray(id, aSelected);
		
		if ( index === -1 ) {
			aSelected.push( id );
		} else {
			aSelected.splice( index, 1 );
		}
		
		$(this).toggleClass('row_selected');
	} );
} );

Server response

The code below shows the latest JSON data that has been returned from the server in response to the Ajax request made by DataTables. This will update as further requests are made.


			
			
			

Other examples

le v�lo � tampa (floride) douanes acier courb� sur ont d�voil� leur dernier projet, 1982 honda cb750 d�capotable.dirig� par mike mundy,ADIDAS EQUIPMENT CUSHION 93 la boutique & # 8217;Adidas Climacool Boat Lace s plus r�cente adaptation caract�ristiques l'�quipage & # 8217;ADIDAS TUBULAR SHADOW KNIT s signature minimaliste propre conception avec la peinture gris et noir sur l'ext�rieur.ajouts comprennent un �cran prot�g� phare, red pod filtres et mono - choc springs parmi beaucoup d'autres am�liorations.Adidas Yeezy Boost 350 V2peut - �tre la plus frappante dans le d�tail le tuyau d'�chappement est saillante sous le si�ge.ils a �t� sur un rouleau cette ann�e avec ses nombreuses collaborations et les rejets, et maintenant,ADIDAS ORIGINALS NMD PRIMEKNIT les japonais basket brand,ADIDAS SPRINGBLADE SCHUHE c'est prendre un retour aux sources avec une nouvelle paire de gel lyte vs.ADIDAS TUBULAR WOMENv�tue d'un haut blanc pur nubuck le & # 8220; winter & # 8221;ADIDAS SPRINGBLADE WOMEN SCHUHE pack publication offre une nouvelle nubuck blanc sur la simplicit� comme si�ge haut de la corde d'une semelle intercalaire,ADIDAS CAMPUS tandis que les lacets cravate le chercher ensemble.comme toujours, la nouvelle - # 8220; hiver pack & # 8221; gel lyte v offre confort incomparable avec son gel technologie situ� dans le rembourrage intercalaire.l'asic gel lyte v & # 8220,women's superstar adidas white & # 8221; est maintenant disponible chez les d�taillants comme quelques environ 145 $us.