{hero}

search.fixed()

Since: DataTables 2.0

Get / set a named search to apply to a table.

Description

This method provides the ability to apply a "fixed" search to a DataTable. They might also be termed sticky or named searches. The primary difference from a standard search term is that a fixed search is not immediately replaced by the next search term applied. It is consistently applied to the table, until either replaced by name or is deleted.

Fixed search terms are particularly useful when you want to layer searches - i.e. add multiple search terms and have the table display the cumulative result.

This interface is usually expected to be used by developers creating a custom search interface for DataTables.

Please be aware that this method sets the fixed search to apply to the table only - it does not actually perform the search. In order to have the search performed and the result shown, use the draw() method, which can be called simply as a chained method of this method.

When using server-side processing, additional logic must be added at the server-side to handle fixed search terms. Additionally, searching by functions is not possible, since the search function is client-side based.

Types

function search.fixed()

Description:

Get a list of the names of searches applied to the table.

Returns:

An API instance that contains the names of the search terms applied to the table.

function search.fixed( name )

Description:

Get the search term used for the given name.

Parameters:
Returns:

The search term that was originally applied.

function search.fixed( name, searchTerm )

Description:

Set a search term to apply to the table, using a name to uniquely identify it.

Parameters:
Returns:

DataTables API instance

Examples

Get an array of current search names:

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

let searches = table.search.fixed().toArray();

Get an expecting search term:

let search = table.search.fixed('mySearch');

Applying a search string:

table.search.fixed('myString', 'Paris');

Applying a search regex:

table.search.fixed('myRegex', /l.*n/i);

Applying a search function:

table.search.fixed('myFunc', (row, data) => {
	return row.includes('New York');
});

Deleting an existing search term:

table.search.fixed('mySearch', null);

Related

The following options are directly related and may also be useful in your application development.