File: count%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 (36 lines) | stat: -rw-r--r-- 1,536 bytes parent folder | download | duplicates (6)
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
<?xml version="1.0" encoding="UTF-8" ?>
<dt-api group="utility">
	<name>count()</name>
	<summary>Get the number of elements that are contained in an API instance</summary>
	<since>1.10.8</since>

	<type type="function">
		<signature>count()</signature>
		<description>Get the number of entries in an API instance's result set, regardless of multi-table grouping (e.g. any data, selected rows, etc).</description>
		<returns type="integer">The number of items in the API instance's result set</returns>
	</type>

	<description>
		If can sometimes be useful to know how many items are contained in an API's result set - a function that is provided by this method.

		It is important to note that the `length` property cannot simply be reliably used itself to determine if the API result set contains any elements or not as the DataTables API is multi-table aware and the result set consists of nested arrays. Therefore we must flatten arrays before being able to use the `length` property. This method does exactly that (i.e. it is a shortcut for `api.flatten().length`).
	</description>

	<example title="Count how many rows there are with the class `selected`"><![CDATA[
var table = $('#example').DataTable();

alert( 'Rows '+table.rows( '.selected' ).count()+' are selected' );

]]></example>

	<example title="Count the number of data entries (i.e. rows) in a table"><![CDATA[
var table = $('#example').DataTable();

if ( ! table.data().count() ) {
	alert( 'Empty table' );
}

]]></example>

	<related>dt-api any()</related>
</dt-api>