diff --git a/docs/app/components/content/examples/table/TableGroupedRowsExample.vue b/docs/app/components/content/examples/table/TableGroupedRowsExample.vue new file mode 100644 index 00000000..9d9b6cc3 --- /dev/null +++ b/docs/app/components/content/examples/table/TableGroupedRowsExample.vue @@ -0,0 +1,203 @@ + + + diff --git a/docs/content/3.components/table.md b/docs/content/3.components/table.md index 5a5c01de..f74e4ed3 100644 --- a/docs/content/3.components/table.md +++ b/docs/content/3.components/table.md @@ -260,6 +260,30 @@ You can use the `expanded` prop to control the expandable state of the rows (can You could also add this action to the [`DropdownMenu`](/components/dropdown-menu) component inside the `actions` column. :: +### With grouped rows + +You can group rows based on a given column value and show/hide sub rows via some button added to the cell using the TanStack Table [Grouping APIs](https://tanstack.com/table/latest/docs/api/features/grouping). + +#### Important parts: + +* Add prop `grouping` to `UTable` component with an array of column ids you want to group by. +* Add prop `grouping-options` to `UTable`. It must include `getGroupedRowModel`, you can import it from `@tanstack/vue-table` or implement your own. +* Expand rows via `row.toggleExpanded()` method on any cell of the row. Keep in mind, it also toggles `#expanded` slot. +* Use `aggregateFn` on column definition to define how to aggregate the rows. +* `agregatedCell` renderer on column definition only works if there is no `cell` renderer. + +::component-example +--- +prettier: true +collapse: true +name: 'table-grouped-rows-example' +highlights: + - 159 + - 169 +class: '!p-0' +--- +:: + ### With row selection You can add a new column that renders a [Checkbox](/components/checkbox) component inside the `header` and `cell` to select rows using the TanStack Table [Row Selection APIs](https://tanstack.com/table/latest/docs/api/features/row-selection).