Add "default" sort/filter/groupBy options for non accessors, rename disableGrouping

This commit is contained in:
Tanner Linsley 2019-11-20 09:35:40 -07:00
parent 50b00b67c5
commit ed3dd9e6b5
5 changed files with 57 additions and 10 deletions

View File

@ -1,3 +1,16 @@
## 7.0.0-beta.13
- Added options
- `defaultCanSort`
- `defaultCanFilter`
- `defaultCanGroupBy`
- `column.defaultCanSort`
- `column.defaultCanFilter`
- `column.defaultCanGroupBy`
- Renamed
- `disableGrouping` to `disableGroupBy`
- `column.disableGrouping` to `column.disableGroupBy`
## 7.0.0-beta.0
- Massive changes to the entire project and library. Please consult the README and documentation for more information regarding these changes.

View File

@ -361,6 +361,10 @@ The following options are supported via the main options object passed to `useTa
- Enables sorting detection functionality, but does not automatically perform row sorting. Turn this on if you wish to implement your own sorting outside of the table (eg. server-side or manual row grouping/nesting)
- `disableSorting: Bool`
- Disables sorting for every column in the entire table.
- `defaultCanSort: Bool`
- Optional
- Defaults to `false`
- If set to `true`, all columns will be sortable, regardless if they have a valid `accessor`
- `disableMultiSort: Bool`
- Disables multi-sorting for the entire table.
- `isMultiSortEvent: Function`
@ -385,6 +389,10 @@ The following options are supported via the main options object passed to `useTa
The following options are supported on any `Column` object passed to the `columns` options in `useTable()`
- `defaultCanSort: Bool`
- Optional
- Defaults to `false`
- If set to `true`, this column will be sortable, regardless if it has a valid `accessor`
- `disableSorting: Bool`
- Optional
- Defaults to `false`
@ -471,6 +479,10 @@ The following options are supported via the main options object passed to `useTa
- Turn this on if you wish to implement your own row filter outside of the table (eg. server-side or manual row grouping/nesting)
- `disableFilters: Bool`
- Disables filtering for every column in the entire table.
- `defaultCanFilter: Bool`
- Optional
- Defaults to `false`
- If set to `true`, all columns will be filterable, regardless if they have a valid `accessor`
- `filterTypes: Object<filterKey: filterType>`
- Must be **memoized**
- Allows overriding or adding additional filter types for columns to use. If a column's filter type isn't found on this object, it will default to using the built-in filter types.
@ -488,6 +500,10 @@ The following options are supported on any `Column` object passed to the `column
- `disableFilters: Bool`
- Optional
- If set to `true`, will disable filtering for this column
- `defaultCanFilter: Bool`
- Optional
- Defaults to `false`
- If set to `true`, this column will be filterable, regardless if it has a valid `accessor`
- `filter: String | Function`
- Optional
- Defaults to `text`

View File

@ -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)

View File

@ -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)

View File

@ -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