
useGroupByuseGroupBy 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: BooldisableGroupBy: Boolaggregations: Object<aggregationKey: aggregationFn>groupByFn: FunctiondefaultGroupByFnstate.groupBy keys provided. It's very rare you would need to customize this function.autoResetGroupBy: Booleantruetrue, the expanded state will automatically reset if any of the following conditions are met:data is changedfalseThe following options are supported on any Column object passed to the columns options in useTable()
Aggregated: Function | React.Component => JSXCell formatterAggregated function for this column could format that value to 1,000 Avg. Visitsaggregate: String | Function(leafValues, aggregatedValues) => anyaverage-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) => anycount-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: Booleanfalsetrue, 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) => voidsetGroupBy: Function(columnIds: Array<String>) => voidThe following properties are available on every Column object returned by the table instance.
canGroupBy: Booleantrue, this column is able to be grouped.useGroupBy related optionsisGrouped: Booleantrue, this column is currently being groupedgroupedIndex: IntgroupBy array.toggleGroupBy: Function(?set: Bool) => voidgetGroupByToggleProps: Function(props) => propsgetGroupByToggleProps hook to extend its functionality.The following properties are available on every Row object returned by the table instance.
groupByID: Stringundefined if the row is an original row from data and not a materialized one from the grouping.groupByVal: anyvalues: Objectvalues objectsubRows: Array<Row>leafRows: Array<Row>depth: Intid: StringgetRowId function, which defaults to chaining parent IDs and joining with a .columnId:groupByVal.isAggregated: Booltrue 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: Booltrue, this cell is a grouped cell, meaning it contains a grouping value and should usually display and expander.isPlaceholder: Booltrue, 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: Booltrue, 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.