diff --git a/.size-snapshot.json b/.size-snapshot.json index 1bfd6d1..0d42416 100644 --- a/.size-snapshot.json +++ b/.size-snapshot.json @@ -1,13 +1,13 @@ { "dist/index.js": { - "bundled": 90278, - "minified": 43057, - "gzipped": 11502 + "bundled": 90287, + "minified": 43056, + "gzipped": 11505 }, "dist/index.es.js": { - "bundled": 89695, - "minified": 42549, - "gzipped": 11382, + "bundled": 89704, + "minified": 42548, + "gzipped": 11385, "treeshaked": { "rollup": { "code": 450, diff --git a/CHANGELOG.md b/CHANGELOG.md index 5218969..9c66bcf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,14 @@ +## 7.0.0-beta.19 + +- Added an `isAggregated` boolean parameter to the `aggregate` function signature + +## 7.0.0-beta.16 + +- Removed service workers from examples +- Fixed a memory leak when `instance` was referenced in function closures +- Fixed an issue where the table would infinitely rerender due to incorrect effect dependencies +- Fixed an issue where row grouping and row selection would not work properly together. + ## 7.0.0-beta.15 - Fixed an issue where `defaultGetResetPageDeps` was using `data` instead of `rows` diff --git a/docs/api.md b/docs/api.md index 989da2b..ba20361 100644 --- a/docs/api.md +++ b/docs/api.md @@ -601,6 +601,12 @@ The following options are supported on any `Column` object passed to the `column - Receives the table instance and cell model as props - Must return valid JSX - This function (or component) formats this column's value when it is being grouped and aggregated, eg. If this column was showing the number of visits for a user to a website and it was currently being grouped to show an **average** of the values, the `Aggregated` function for this column could format that value to `1,000 Avg. Visits` +- `aggregate: String | [String, String] | Function(values, rows, isAggregated: Bool) => any` + - If a single `String` is passed, it must be the key of either a user defined or predefined `aggregations` function. + - If a tuple array of `[String, String]` is passed, both must be a key of either a user defined or predefined `aggregations` function. + - The first is used to aggregate raw values, eg. `sum`-ing raw values together + - The second is used to aggregate values that have already been aggregated, eg. `average`-ing the sums produced by the raw aggregation level + - If a `Function` is passed, this function will receive the `values`, original `rows` of those values, and an `isAggregated` `Bool` of whether or not the values and rows have already been aggregated. - `disableGroupBy: Boolean` - Defaults to `false` - If `true`, will disable grouping for this column. diff --git a/package.json b/package.json index e701220..b611b7c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "react-table", - "version": "7.0.0-beta.17", + "version": "7.0.0-beta.19", "description": "A fast, lightweight, opinionated table and datagrid built on React", "license": "MIT", "homepage": "https://github.com/tannerlinsley/react-table#readme", diff --git a/src/plugin-hooks/useGroupBy.js b/src/plugin-hooks/useGroupBy.js index de39cb1..c0dc320 100755 --- a/src/plugin-hooks/useGroupBy.js +++ b/src/plugin-hooks/useGroupBy.js @@ -163,7 +163,7 @@ function useMain(instance) { // Find the columns that can or are aggregating // Uses each column to aggregate rows into a single value - const aggregateRowsToValues = (rows, isSourceRows) => { + const aggregateRowsToValues = (rows, isAggregated) => { const values = {} flatColumns.forEach(column => { @@ -184,7 +184,7 @@ function useMain(instance) { `React Table: Complex aggregators must have 2 values, eg. aggregate: ['sum', 'count']. More info above...` ) } - if (isSourceRows) { + if (isAggregated) { aggregator = aggregator[1] } else { aggregator = aggregator[0] @@ -197,7 +197,7 @@ function useMain(instance) { : userAggregations[aggregator] || aggregations[aggregator] if (aggregateFn) { - values[column.id] = aggregateFn(columnValues, rows) + values[column.id] = aggregateFn(columnValues, rows, isAggregated) } else if (aggregator) { console.info({ column }) throw new Error( @@ -235,10 +235,7 @@ function useMain(instance) { subRows = groupRecursively(subRows, depth + 1, path) - const values = aggregateRowsToValues( - subRows, - depth + 1 >= groupBy.length - ) + const values = aggregateRowsToValues(subRows, depth < groupBy.length) const row = { isAggregated: true,