useFilters
useFilters
is the hook that implements row filtering - filtering based upon the data in specific columns. It can be used in conjunction with useGlobalFilter
, which involves filtering rows based upon data in any column in a given row. It is important to note that this hook can be used either before or after useGlobalFilter
, 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.filters: Array<Object<id: String, value: any>>
id
and a corresponding filter value
. This information is stored in state since the table is allowed to manipulate the filter through user interaction.manualFilters: Bool
disableFilters: Bool
defaultCanFilter: Bool
false
true
, all columns will be filterable, regardless if they have a valid accessor
filterTypes: Object<filterKey: filterType>
filter
type isn't found on this object, the column will default to using the built-in filter types.autoResetFilters: Boolean
true
true
, the filters
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
options in useTable()
Filter: Function | React.Component => JSX
disableFilters: Bool
true
, filtering for this column will be disableddefaultCanFilter: Bool
false
true
, this column will be filterable, regardless if it has a valid accessor
filter: String | Function(rows: Array<Row>, columnIds: Array<ColumnId: String>, filterValue) => Rows[]
text
string
is passed, the function with that name will be used from either the custom filterTypes
table option (if specified) or from the built-in filtering types object.function
is passed:rows
to filter, an array of columnIds
(being a single-element array with the column ID being filtered), and filterValue
, being the current value of the filter being appliedArray
of rows, being the remaining rows that have not been filtered outThe following values are provided to the table instance
:
state.filters: Array<Object<id: String, value: any>>
filters
values located on the state object. This is an array of objects, each having a column id
and its current corresponding filter value
. Example: [{ id: 'name', value: 'Jane'}, { id: 'age', value: 21 }]
rows: Array<Row>
preFilteredRows: Array<Row>
rows
do not contain every possible option.setFilter: Function(columnId, filterValue) => void
setAllFilters: Function(filtersObjectArray) => void
filtersObjectArray
is an array of objects with id
and value
keys. Example: [{ id: 'columnAccessor', value: 'valueToFilter' }]
setAllFilters
with an array, even if that array is empty. Example: setAllFilters([])
The following properties are available on every Column
object returned by the table instance:
canFilter: Bool
setFilter: Function(filterValue) => void
filterValue: any
filters
objectpreFilteredRows: Array<row>
filteredRows: Array<row>
The best JavaScript newsletter! Delivered every Monday to over 76,000 devs.