{hero}

splice()

Since: DataTables 1.10

Modify the contents of an Api instance's result set, adding or removing items from it as required.

Description

The methods of pop(), 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 inherit 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.

Type

function splice( index, howMany [, value_1 [, ... ] ] )

Description:

Modify the contents of an Api instance's result set, adding or removing items from it as required.

Parameters:
Returns:

An array of the items which were removed. If no elements were removed, an empty array is returned.

Example

Search for a value using indexOf() and replace it using splice() if found.:

var table = new DataTable('#myTable');

// 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);
}