<?xml version="1.0" encoding="UTF-8" ?>
<dt-example table-type="html" order="11">

<css lib="datatables" />
<js lib="jquery" />
<js lib="datatables" />

<title>Using API in callbacks</title>
<js><![CDATA[

$(document).ready(function() {
	$('#example').DataTable( {
		"initComplete": function () {
			var api = this.api();
			api.$('td').click( function () {
				api.search( this.innerHTML ).draw();
			} );
		}
	} );
} );

]]></js>

<info><![CDATA[

There are times when you may wish to call API functions inside the DataTables callback functions (for example `dt-init initComplete`, `dt-init rowCallback` etc). The complicating issue with this is that the object hasn't fully initialised, so you can't assign the result to a variable and then use that variable in the callback. However, all of DataTables' callback functions are executed in the scope of the DataTable instance, so you can use the Javascript special variable `this` to access the API (`this.api()` will give an API instance) as `this` is the `tag table` node.

In this example you will be able to see that the `dt-api $()` method is used to get all cell nodes in the table's body and then act on them (in this case adding a click event). The action here is to apply a filter to the table with the value of what is in each cell.

It is also worth noting that this same effect could be achieved by attaching a delegated click event after the table has been initialised - but the example shows the use of the API inside the callbacks!

]]></info>

</dt-example>
