column().search.fixed()
Get / set a named search to apply to a column.
Description
Just as search.fixed()
applies a "fixed" search term to the whole table, this method can be used to apply a search term to a specific column.
The fixed search (which might also be termed sticky or named searches) provides a way to easily add cumulative search terms to the table. You can add multiple independent search terms, and DataTables will combine them (AND logic) displaying the result of all search terms that have been applied.
Please be aware that this method sets the fixed search to apply to the column 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.
Types
function column().search.fixed()
- Description:
Get a list of the names of searches applied to the column.
- Returns:
An API instance that contains the names of the search terms applied to the column.
function column().search.fixed( name )
- Description:
Get the search term used for the given name.
- Returns:
The search term that was originally applied.
function column().search.fixed( name, searchTerm )
- Description:
- Parameters:
Name Type Optional 1 name
No Treat as a regular expression (
true
) or not (default,false
).2 input
No The search term to apply to the table.
Use
null
for this value to delete an existing search term.If given as a string, it will be applied to the table's search using DataTables "smart" search (see
search()
).If working with a regular expression, the data given is the search data for the cells in column in question.
In the case of a function the function is called for each row with four parameters which are passed in:
- The search string of data from all searchable columns in the table
- The row's original data object
- The row's data index
- The columns's data index
A boolean value should be returned:
true
to keep the row,false
to filter it out.- Returns:
DataTables API instance
Examples
Get an array of current search names:
let table = new DataTable('#myTable');
let searches = table
.column(0)
.search.fixed()
.toArray();
Get an expecting search term:
let search = table.column(1).search.fixed('mySearch');
Applying a search string:
table.column('.cities').search.fixed('myString', 'Paris');
Applying a search regex:
table.column(0).search.fixed('myRegex', /l.*n/i);
Applying a search function:
table.column(-1).search.fixed('myFunc', (cell, data) => {
return cell > 50;
});
Deleting an existing search term:
table.column(0).search.fixed('mySearch', null);
Related
The following options are directly related and may also be useful in your application development.