mirror of
https://github.com/gosticks/react-table.git
synced 2026-10-04 14:56:59 +00:00
Relocate columns and row logic, fix columns and useGroupBy to be more pure
Since useColumns was relying on groupBy logic, this was code smell. I wanted useGroupBy to be able to add that logic all by itself and not have to have dependencies in the core of the table. To fix that, I've moved the core column and row logic to the useTable hook and added a new hook 'columnsBeforeHeaderGroups' to allow useGroupBy to do what i needs in a more pure way.
This commit is contained in:
@@ -14,14 +14,11 @@ const propTypes = {
|
||||
// General
|
||||
columns: PropTypes.arrayOf(
|
||||
PropTypes.shape({
|
||||
filterFn: PropTypes.func,
|
||||
filterAll: PropTypes.bool,
|
||||
canFilter: PropTypes.bool,
|
||||
disableFilters: PropTypes.bool,
|
||||
Filter: PropTypes.any,
|
||||
})
|
||||
),
|
||||
|
||||
filterFn: PropTypes.func,
|
||||
manualFilters: PropTypes.bool,
|
||||
}
|
||||
|
||||
@@ -99,12 +96,12 @@ export const useFilters = props => {
|
||||
|
||||
hooks.columns.push(columns => {
|
||||
columns.forEach(column => {
|
||||
const { id, accessor, canFilter } = column
|
||||
const { id, accessor, disableFilters: columnDisableFilters } = column
|
||||
|
||||
// Determine if a column is filterable
|
||||
column.canFilter = accessor
|
||||
? getFirstDefined(
|
||||
canFilter,
|
||||
columnDisableFilters,
|
||||
disableFilters === true ? false : undefined,
|
||||
true
|
||||
)
|
||||
@@ -143,13 +140,12 @@ export const useFilters = props => {
|
||||
// Find the filters column
|
||||
const column = columns.find(d => d.id === columnID)
|
||||
|
||||
column.preFilteredRows = filteredSoFar
|
||||
|
||||
// Don't filter hidden columns or columns that have had their filters disabled
|
||||
if (!column || column.filterable === false) {
|
||||
if (!column) {
|
||||
return filteredSoFar
|
||||
}
|
||||
|
||||
column.preFilteredRows = filteredSoFar
|
||||
|
||||
const filterMethod = getFilterMethod(
|
||||
column.filter,
|
||||
userFilterTypes || {},
|
||||
|
||||
Reference in New Issue
Block a user