DataTables events (post-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). You can do this at any time, although if you apply the handlers after the table has been initialised there is an extra set. Rather then querying the DOM to get all rows (since they aren't there) you can use the '$' API method that DataTables provides which does a jQuery selector on the whole table and returns a jQuery object.

This example shows the tooltip plug-in being applied to the table after initialisation.

Live example

Rendering engineBrowserPlatform(s)Engine versionCSS grade
Rendering engineBrowserPlatform(s)Engine versionCSS 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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
$(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 );
    } );
     
    /* Init DataTables */
    var oTable = $('#example').dataTable();
     
    /* Apply the tooltips */
    oTable.$('tr').tooltip( {
        "delay": 0,
        "track": true,
        "fade": 250
    } );
} );

Other examples