File: splice%28%29.xml

package info (click to toggle)
datatables.js 1.11.5%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 22,848 kB
  • sloc: javascript: 65,075; xml: 10,712; php: 4,741; sh: 544; makefile: 18
file content (48 lines) | stat: -rw-r--r-- 2,314 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
37
38
39
40
41
42
43
44
45
46
47
48
<?xml version="1.0" encoding="UTF-8" ?>
<dt-api group="utility">
	<name>splice()</name>
	<summary>Modify the contents of an Api instance's result set, adding or removing items from it as required.</summary>
	<since>1.10</since>

	<type type="function">
		<signature>splice( index, howMany [, value_1 [, ... ] ] )</signature>
		<description>Modify the contents of an Api instance's result set, adding or removing items from it as required.</description>
		<parameter type="integer" name="index">
			Index at which to start modifying the Api instance's result set.
		</parameter>
		<parameter type="integer" name="howMany">
			Number of elements to remove from the result set. This can be 0 if you wish to only add new items.
		</parameter>
		<parameter type="*" name="value_1" default="undefined">
			Item to add to the result set at the index specified by the first parameter. Multiple items can be added in a single call by adding them as additional parameters.
		</parameter>
		<returns type="array">An array of the items which were removed. If no elements were removed, an empty array is returned.</returns>
	</type>

	<description>
		The methods of `dt-api pop()`, `dt-api shift()` etc can be useful to modify an Api instance's result set, but they are restricted to operating at the start of the end of the result set. This method can be used to modify the result set at any point.

		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.splice` 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 `splice`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/splice).
	</description>

	<example title="Search for a value using `dt-api indexOf()` and replace it using `dt-api splice()` if found."><![CDATA[
var table = $('#example').DataTable();

// Get column data
var data = table
	.column( 0 )
	.data();

// Find the first instance of `32`
var idx = data.indexOf( 32 );

// Replace with `33`
if ( idx >= 0 ) {
	data.splice( idx, 1, 33 );
}

]]></example>

</dt-api>