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.
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.
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.
Statefully Managed
Plugin
PluginProperties
Type: Object
Properties
filterMethodA custom method used to filter the data by the searched value when the search is submitted. Must return the filtered data.searchValuestring When statefully managing this plugin, initializes the submitted search state and updates the search input on change.onSearchValueChangeA callback that is fired when the search value changes.onSearchCallback that is called when the search is submitted.onClearCallback 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
searchedValuestring The submitted text value from the search input.
Returns Array<Object> The filtered data (rows).
onSearch
Type: Function
Parameters
eventReact.SyntheticEvent The submit event.searchedValuestring The submitted text value from the search input.
onSearchValueChange
Type: Function
Parameters
eventReact.SyntheticEvent The change event.payloadObject 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.