DataTables events (pre-initialisation) example

Preamble

Events which are assigned to the table elements are retained by DataTables such that they will still work as you would expect, even after changing the sort order etc. (no need to reapply the event handlers). If you apply the event handlers before you initialise DataTables, you just do this in the normal way. This is shown in this example where the call $('#example tbody tr[title]').tooltip(); is made before the table is initialised.

Live example

Show entries
Search:
Rendering engine Browser Platform(s) Engine version CSS grade
Rendering engine Browser Platform(s) Engine version CSS grade
Gecko Firefox 1.0 Win 98+ / OSX.2+ 1.7 A
Gecko Firefox 1.5 Win 98+ / OSX.2+ 1.8 A
Gecko Firefox 2.0 Win 98+ / OSX.2+ 1.8 A
Gecko Firefox 3.0 Win 2k+ / OSX.3+ 1.9 A
Gecko Camino 1.0 OSX.2+ 1.8 A
Gecko Camino 1.5 OSX.3+ 1.8 A
Gecko Netscape 7.2 Win 95+ / Mac OS 8.6-9.2 1.7 A
Gecko Netscape Browser 8 Win 98SE+ 1.7 A
Gecko Netscape Navigator 9 Win 98+ / OSX.2+ 1.8 A
Gecko Mozilla 1.0 Win 95+ / OSX.1+ 1 A
Showing 1 to 10 of 57 entries

Initialisation code

$(document).ready(function() {
	/*
	 * First step is to create title attributes for the rows in the table
	 * This isn't needed if the required 'title' attribute is already set in the HTML in the
	 * DOM 
	 */
	$('#example tbody tr').each( function() {
		var sTitle;
		var nTds = $('td', this);
		var sBrowser = $(nTds[1]).text();
		var sGrade = $(nTds[4]).text();
		
		if ( sGrade == "A" )
			sTitle =  sBrowser+' will provide a first class (A) level of CSS support.';
		else if ( sGrade == "C" )
			sTitle = sBrowser+' will provide a core (C) level of CSS support.';
		else if ( sGrade == "X" )
			sTitle = sBrowser+' does not provide CSS support or has a broken implementation. Block CSS.';
		else
			sTitle = sBrowser+' will provide an undefined level of CSS support.';
		
		this.setAttribute( 'title', sTitle );
	} );
	
	/* Apply the tooltips */
	$('#example tbody tr[title]').tooltip( {
		"delay": 0,
		"track": true,
		"fade": 250
	} );
	
	/* Init DataTables */
	$('#example').dataTable();
} );

Other examples

Basic initialisation

Advanced initialisation

Data sources

Server-side processing

API

Plug-ins

Please refer to the DataTables documentation for full information about its API properties and methods.