Examples
Aggregation and Grouping Example
A Shadcn Table example demonstrating aggregation and grouping. See how you can group rows by a column and aggregate the values of other columns.
Grouping and Aggregation features are usually hard to implement, but ST (thanks to TanStack Table) makes it easy. Once enabled, simply click the vertical ellipses (⋮) icon for the column you want to group by and select Group by (column name).
You can group by a single column or multiple columns at a time. Then, you can run aggregations on grouped columns to calculate totals, averages, max, min, etc.
The Grouping and Aggregation features work hand in hand with the Expanding and Sorting features. Try grouping by various columns in the example below and sorting by the aggregated columns, such as "age" or "salary".
See the Column Grouping and Aggregation docs for more information.
Try it
- Click the arrow on
Alabama. Its rows hide; the oldest age and average salary stay. - Click
Genderand chooseGroup by Gender. Each state splits by gender with its own totals. - Click
Salaryand chooseSort descending. Inside each state the highest salary comes first.