mirror of
https://github.com/gosticks/react-table.git
synced 2026-08-12 21:10:24 +00:00
Add "default" sort/filter/groupBy options for non accessors, rename disableGrouping
This commit is contained in:
@@ -37,6 +37,7 @@ function useMain(instance) {
|
||||
flatColumns,
|
||||
filterTypes: userFilterTypes,
|
||||
manualFilters,
|
||||
defaultCanFilter = false,
|
||||
disableFilters,
|
||||
state: { filters },
|
||||
setState,
|
||||
@@ -108,7 +109,12 @@ function useMain(instance) {
|
||||
}
|
||||
|
||||
flatColumns.forEach(column => {
|
||||
const { id, accessor, disableFilters: columnDisableFilters } = column
|
||||
const {
|
||||
id,
|
||||
accessor,
|
||||
defaultCanFilter: columnDefaultCanFilter,
|
||||
disableFilters: columnDisableFilters,
|
||||
} = column
|
||||
|
||||
// Determine if a column is filterable
|
||||
column.canFilter = accessor
|
||||
@@ -117,7 +123,7 @@ function useMain(instance) {
|
||||
disableFilters === true ? false : undefined,
|
||||
true
|
||||
)
|
||||
: false
|
||||
: getFirstDefined(columnDefaultCanFilter, defaultCanFilter, false)
|
||||
|
||||
// Provide the column a way of updating the filter value
|
||||
column.setFilter = val => setFilter(column.id, val)
|
||||
|
||||
@@ -27,13 +27,13 @@ const propTypes = {
|
||||
PropTypes.oneOfType([PropTypes.func, PropTypes.string])
|
||||
),
|
||||
]),
|
||||
disableGrouping: PropTypes.bool,
|
||||
disableGroupBy: PropTypes.bool,
|
||||
Aggregated: PropTypes.any,
|
||||
})
|
||||
),
|
||||
groupByFn: PropTypes.func,
|
||||
manualGrouping: PropTypes.bool,
|
||||
disableGrouping: PropTypes.bool,
|
||||
disableGroupBy: PropTypes.bool,
|
||||
aggregations: PropTypes.object,
|
||||
}
|
||||
|
||||
@@ -76,7 +76,8 @@ function useMain(instance) {
|
||||
flatHeaders,
|
||||
groupByFn = defaultGroupByFn,
|
||||
manualGroupBy,
|
||||
disableGrouping,
|
||||
defaultCanGroupBy,
|
||||
disableGroupBy,
|
||||
aggregations: userAggregations = {},
|
||||
hooks,
|
||||
plugins,
|
||||
@@ -87,17 +88,22 @@ function useMain(instance) {
|
||||
ensurePluginOrder(plugins, [], 'useGroupBy', ['useSortBy', 'useExpanded'])
|
||||
|
||||
flatColumns.forEach(column => {
|
||||
const { id, accessor, disableGrouping: columnDisableGrouping } = column
|
||||
const {
|
||||
id,
|
||||
accessor,
|
||||
defaultGroupBy: defaultColumnGroupBy,
|
||||
disableGroupBy: columnDisableGrouping,
|
||||
} = column
|
||||
column.isGrouped = groupBy.includes(id)
|
||||
column.groupedIndex = groupBy.indexOf(id)
|
||||
|
||||
column.canGroupBy = accessor
|
||||
? getFirstDefined(
|
||||
columnDisableGrouping === true ? false : undefined,
|
||||
disableGrouping === true ? false : undefined,
|
||||
disableGroupBy === true ? false : undefined,
|
||||
true
|
||||
)
|
||||
: false
|
||||
: getFirstDefined(defaultColumnGroupBy, defaultCanGroupBy, false)
|
||||
|
||||
if (column.canGroupBy) {
|
||||
column.toggleGroupBy = () => toggleGroupBy(column.id)
|
||||
|
||||
@@ -55,6 +55,7 @@ function useMain(instance) {
|
||||
orderByFn = defaultOrderByFn,
|
||||
sortTypes: userSortTypes,
|
||||
manualSorting,
|
||||
defaultCanSort,
|
||||
disableSorting,
|
||||
disableSortRemove,
|
||||
disableMultiRemove,
|
||||
@@ -162,7 +163,12 @@ function useMain(instance) {
|
||||
|
||||
// Add the getSortByToggleProps method to columns and headers
|
||||
flatHeaders.forEach(column => {
|
||||
const { accessor, disableSorting: columnDisableSorting, id } = column
|
||||
const {
|
||||
accessor,
|
||||
canSort: defaultColumnCanSort,
|
||||
disableSorting: columnDisableSorting,
|
||||
id,
|
||||
} = column
|
||||
|
||||
const canSort = accessor
|
||||
? getFirstDefined(
|
||||
@@ -170,7 +176,7 @@ function useMain(instance) {
|
||||
disableSorting === true ? false : undefined,
|
||||
true
|
||||
)
|
||||
: false
|
||||
: getFirstDefined(defaultCanSort, defaultColumnCanSort, false)
|
||||
|
||||
column.canSort = canSort
|
||||
|
||||
|
||||
Reference in New Issue
Block a user