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 35 36 37 38 39 40 41 42
|
<?xml version="1.0" encoding="UTF-8" ?>
<dt-api group="utility">
<name>each()</name>
<summary>Iterate over the contents of the API result set.</summary>
<since>1.10</since>
<type type="function">
<signature>each( fn )</signature>
<description>Iterate over the contents of the API result set.</description>
<parameter type="function" name="fn">
Callback function which is called for each item in the API instance result set. The callback is called with three parameters:
* The element value
* The element index in the result set
* The API instance being traversed
No return value is expected.
</parameter>
<returns type="DataTables.Api">Original API instance that was used. For chaining.</returns>
</type>
<description>
This method makes use of the fact that DataTables API objects are "array like", in that they inherent a lot of the abilities and methods of the Javascript `Array` type.
Note that when working with the plural methods such as `dt-api rows()` and `dt-api columns()` you may wish to use the `dt-api rows().every()`, `dt-api columns().every()` and `dt-api cells().every()` methods to iterate over each row, column or cell with the context set to that table element. This might sound a little complicated, but it can significantly simplify your code! Please refer to the documentation for each of the `every` methods for full details.
The `dt-api each()` method is a proxy for the Javascript `Array.prototype.forEach` method and is provided as a utility method for the DataTables API. For more information about the original method, please refer to the [Mozilla MDN documentation for `forEach`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/forEach). In browsers which do not support `forEach` natively, a polyfill is provided to allow this DataTables method to operate as expected.
</description>
<example title="Loop over the data from a column"><![CDATA[
var table = $('#example').DataTable();
table
.column( 0 )
.data()
.each( function ( value, index ) {
console.log( 'Data in index: '+index+' is: '+value );
} );
]]></example>
</dt-api>
|