File: reduce%28%29.xml

package info (click to toggle)
datatables.js 1.10.13%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 6,232 kB
  • ctags: 1,329
  • sloc: xml: 10,249; php: 4,387; sh: 492; makefile: 21
file content (48 lines) | stat: -rw-r--r-- 2,665 bytes parent folder | download | duplicates (3)
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
43
44
45
46
47
48
<?xml version="1.0" encoding="UTF-8" ?>
<dt-api group="utility">
	<name>reduce()</name>
	<summary>Apply a callback function against and accumulator and each element in the Api's result set (left-to-right).</summary>
	<since>1.10</since>

	<type type="function">
		<signature>reduce( fn [, initialValue ] )</signature>
		<description>Apply a callback function against and accumulator and each element in the Api's 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 four parameters:

			* Current accumulator value, or `initialValue` if supplied in the first callback
			* Current element value
			* The element index in the result set
			* The API instance being traversed

			The callback should return the value to be used as the accumulator for the next loop (first parameter in the callback).
		</parameter>
		<parameter type="*" name="initialValue" default="">
			Value to use as the first argument of the first call to the `fn` callback.
		</parameter>
		<returns type="*">Result from the final call to the `fn` callback function.</returns>
	</type>

	<description>
		This method can be used to accumulate data from a result set into a single value. A good example is summing the values from a column of data. A more complete definition of the Array reduce method, which this method is based upon, can be found on the [Mozilla MDN documentation for `reduce`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reduce).

		Note that the traversal of the elements in the result set in this method is left-to-right (i.e. 0 to `length`). `dt-api reduceRight()` is available for transversal in the opposite direction.

		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.

		In this case, this method is a proxy for the Javascript `Array.prototype.reduce` 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 `reduce`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reduce). In browsers which do not support `reduce` natively, a polyfill is provided to allow this DataTables method to operate as expected.
	</description>

	<example title="Sum the data in a column"><![CDATA[
var table = $('#example').DataTable();

var sum = table
	.column( 0 )
	.data()
	.reduce( function ( a, b ) {
		return a + b;
	} );

]]></example>

</dt-api>