useGroupBy
useGroupBy
is the hook that implements row grouping and aggregation.
getGroupByToggleProps()
function can be used to generate the props needed to make a clickable UI element that will toggle the grouping on or off for a specific column.toggleGroupBy
functions are also made available for programmatic grouping.The following options are supported via the main options object passed to useTable(options)
initialState.groupBy: Array<String>
manualGroupBy: Bool
disableGroupBy: Bool
aggregations: Object<aggregationKey: aggregationFn>
groupByFn: Function
defaultGroupByFn
state.groupBy
keys provided. It's very rare you would need to customize this function.autoResetGroupBy: Boolean
true
true
, the expanded
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()
Aggregated: Function | React.Component => JSX
Cell
formatterAggregated
function for this column could format that value to 1,000 Avg. Visits
aggregate: String | Function(leafValues, aggregatedValues) => any
average
-ing the ages of many cells in a table"String
is passed, it must be the key of either a user defined or predefined aggregations
function.Function
is passed, this function will receive both the leaf-row values and (if the rows have already been aggregated, the previously aggregated values) to be aggregated into a single value.(leafValues, aggregatedValues) => aggregatedValue
where leafValues
is a flat array containing all leaf rows currently grouped at the aggregation level and aggregatedValues
is an array containing the aggregated values from the immediate child sub rows. Each has purpose in the types of aggregations they power where optimizations are made for either accuracy or performance.aggregateValue: String | Function(values, row, column) => any
count
-ing the unique number of items in a cell's array value before sum
-ing that count across the table.String
is passed, it must be the key of either a user defined or predefined aggregations
function.Function
is passed, this function will receive the cell's accessed value, the original row
object and the column
associated with the celldisableGroupBy: Boolean
false
true
, will disable grouping for this column.The following values are provided to the table instance
:
rows: Array<Row>
preGroupedRows: Array<Row>
toggleGroupBy: Function(columnId: String, ?set: Bool) => void
setGroupBy: Function(columnIds: Array<String>) => void
The following properties are available on every Column
object returned by the table instance.
canGroupBy: Boolean
true
, this column is able to be grouped.useGroupBy
related optionsisGrouped: Boolean
true
, this column is currently being groupedgroupedIndex: Int
groupBy
array.toggleGroupBy: Function(?set: Bool) => void
getGroupByToggleProps: Function(props) => props
getGroupByToggleProps
hook to extend its functionality.The following properties are available on every Row
object returned by the table instance.
groupByID: String
undefined
if the row is an original row from data
and not a materialized one from the grouping.groupByVal: any
values: Object
values
objectsubRows: Array<Row>
leafRows: Array<Row>
depth: Int
id: String
getRowId
function, which defaults to chaining parent IDs and joining with a .
columnId:groupByVal
.isAggregated: Bool
true
if the row is an aggregated rowThe following additional properties are available on every Cell
object returned in an array of cells
on every row object.
isGrouped: Bool
true
, this cell is a grouped cell, meaning it contains a grouping value and should usually display and expander.isPlaceholder: Bool
true
, this cell is a repeated value cell, meaning it contains a value that is already being displayed elsewhere (usually by a parent row's cell).isAggregated: Bool
true
, this cell's value has been aggregated and should probably be rendered with the Aggregated
cell renderer.The best JavaScript newsletter! Delivered every Monday to over 76,000 devs.