<?xml version="1.0" encoding="UTF-8" ?>
<dt-api group="rows">
	<name>rows().every()</name>
	<summary>Iterate over each selected row, with the function context set to be the row in question.</summary>
	<since>1.10.6</since>

	<type type="function">
		<signature>rows().every( fn )</signature>
		<description>Iterate over each selected row</description>
		<parameter type="function" name="fn">
			Function to execute for every row selected. The function's content is set to be an API instance for the row in question.

			As of DataTables 1.10.8 the function is passed the following parameters:

			1. Row index
			2. Table loop counter
			3. Row loop counter
			4. Undefined (present only for consistency)

			No return value is expected or acted upon.
		</parameter>
		<returns type="DataTables.Api">DataTables API instance of the selected rows.</returns>
	</type>

	<description>
		A typical operation with the DataTable API is to perform an operation on a collection of rows - a common action is performed on each row, adding event handlers, updating data, etc. This iteration of the rows can be performed a number of ways in DataTables, each with its own advantages:

		* `dt-api rows().every()`
		* `dt-api iterator()`
		* `dt-api each()`

		This `dt-api rows().every()` method is likely to be the most useful in the majority of cases as it sets the context of the callback function to be the `dt-api row()` instance for the row in question (normally a callback in the DataTables API has its context set to be at the top level API hierarchy). In simple terms this means you have the methods such as `dt-api row().data()` available as `this.data()` in the callback given to this method.

		Consider the following example using `dt-api each()`, which iterates over the row indexes that have been selected - we are required to get the `dt-api row()` object for each row to be able to work with it directly:

		```js
		table.rows().eq(0).each( function ( index ) {
			var row = table.row( index );

			var data = row.data();
			// ... do something with data(), or row.node(), etc
		} );
		```

		Using `dt-api rows().every()` this can be rewritten as:

		```js
		table.rows().every( function ( rowIdx, tableLoop, rowLoop ) {
			var data = this.data();
			// ... do something with data(), or this.node(), etc
		} );
		```

		Although a relatively simple optimisation in terms of code presentation, it can make the code much more readable and intuitive.

		The other advantage is that the table context is automatically handled - in the first example above where `dt-api each()` is used, the `dt-api eq()` method is used to select the information from the first table in the API's context only, introducing complexity if multiple tables are used. In `dt-api rows().every()` the table context is automatically set to the appropriate table for each row that has been selected.
	</description>

	<example title="Add a child row to all rows, passing in a jQuery created `dt-tag tr` element and show all child rows"><![CDATA[
var table = $('#example').DataTable();

table.rows().every( function ( rowIdx, tableLoop, rowLoop ) {
	this
		.child(
			$(
				'<tr>'+
					'<td>'+rowIdx+'.1</td>'+
					'<td>'+rowIdx+'.2</td>'+
					'<td>'+rowIdx+'.3</td>'+
					'<td>'+rowIdx+'.4</td>'+
				'</tr>'
			)
		)
		.show();
} );

]]></example>

	<example title="Update all rows in the table, redrawing only when complete"><![CDATA[
var table = $('#example').DataTable();

table.rows().every( function ( rowIdx, tableLoop, rowLoop ) {
	var d = this.data();

	d.counter++; // update data source for the row

	this.invalidate(); // invalidate the data DataTables has cached for this row
} );

// Draw once all updates are done
table.draw();

]]></example>


	<related type="api">columns().every()</related>
	<related type="api">cells().every()</related>
	<related type="api">each()</related>
	<related type="api">iterator()</related>
</dt-api>
