Skip to main content

useSearch

The useSearch plugin adds basic search functionality to the DataTable.

Without providing any configuration to the plugin, it will perform a string match on each column in every row to determine whether the row should be displayed.

Result
Loading...
Live Editor

With Custom Search Filter

If you'd like to customize the search functionality of the useSearch plugin, you can provide a configuration object to the useSearch hook with a filterMethod defined. Your filterMethod callback should return the filtered set of data.

NOTE: When providing a custom filter method, make sure to ignore the id field in each row. Otherwise you run the risk of displaying a row that matches based on the ID but not on any of the columns that are displayed to the user.

Result
Loading...
Live Editor

With Async Data

If your search requires an asynchronous call to fetch a new set of data, you can provide an onSearch and an onClear callback in the configuration object for the useSearch hook. Unlike the filterMethod example above, your onSearch and onClear callbacks should ultimately update your data array stored in state so you can pass it back down into the DataTable through the data prop.

Result
Loading...
Live Editor

Statefully Managed

Result
Loading...
Live Editor

Plugin

PluginProperties

Type: Object

Properties

  • filterMethod A custom method used to filter the data by the searched value when the search is submitted. Must return the filtered data.
  • searchValue string When statefully managing this plugin, initializes the submitted search state and updates the search input on change.
  • onSearchValueChange A callback that is fired when the search value changes.
  • onSearch Callback that is called when the search is submitted.
  • onClear Callback that is called when the search clear button is clicked.

useSearch

Create a plugin hook that enables DataTable searching by adding the search component to the table bar.

Parameters

  • props (optional, default {})

Returns Plugin

filterMethod

Type: Function

Parameters

  • searchedValue string The submitted text value from the search input.

Returns Array<Object> The filtered data (rows).

onSearch

Type: Function

Parameters

  • event React.SyntheticEvent The submit event.
  • searchedValue string The submitted text value from the search input.

onSearchValueChange

Type: Function

Parameters

  • event React.SyntheticEvent The change event.
  • payload Object An object containing the value of the search input.

onChange

Callback method when input value is changed.

Parameters

Returns any void

Meta

  • deprecated: As of v11 payload will no longer include filter. Use onFilterChange instead.

onBlur

Callback method when input is blurred.

Parameters

Returns any void

onSubmit

Callback when submitted.

Parameters

Returns any void

onClear

Callback method when clear button is clicked.