useGlobalFilter
useGlobalFilter
is the hook that implements global row filtering – in other words, filtering based upon data that may be in any column in a given row. This is often useful as a free-text search across all columns simultaneously. It can be used in conjunction with useFilters
, which involves filtering based upon data in specific columns. It is important to note that this hook can be used either before or after useFilters
, depending on the performance characteristics you want to code for.
The following options are supported via the main options object passed to useTable(options)
initialState.globalFilter: any
globalFilter: String | Function(rows: Array<Row>, columnIds: Array<ColumnId: String>, globalFilterValue) => Rows[]
text
string
is passed, the function with that name will be used from either the custom filterTypes
table option (if specified) or used from the built-in filtering types object.function
is passed:rows
to filter, an array of columnIds
(being the column IDs that global filtering is being applied to), and globalFilterValue
, being the current value of the global filterArray
of rows, being the remaining rows that have not been filtered out according to the globalFilterValue
specifiedmanualGlobalFilter: Bool
disableGlobalFilter: Bool
filterTypes: Object<filterKey: filterType>
globalFilter
type isn't found on this object, the table will default to using the built-in filter types.autoResetGlobalFilter: Boolean
true
true
, the globalFilter
state will automatically reset if any of the following conditions are met:data
is changedfalse
The following options are supported on any Column
object passed to the columns
option in useTable()
:
disableGlobalFilter: Bool
true
, global filtering will be disabled for this columnThe following values are provided to the table instance
:
state.globalFilter: String
globalFilter
value, located on the state object.rows: Array<Row>
preGlobalFilteredRows: Array<Row>
rows
do not contain every possible option.setGlobalFilter: Function(filterValue) => void
The best JavaScript newsletter! Delivered every Monday to over 76,000 devs.