Grouping

Row grouping allows users to collapse rows into hierarchical groups based on column values. Click the group icon in a column header to group by that column. Grouped rows display a count of their subRows and can be expanded to show the underlying data. Use an aggregationFn on columns like "Visits" to aggregate values (e.g., sum) when rows are grouped.


Username
Account Status
Role
Avg Session Duration
Company Name
Last Visited At
Visit Count
Royal_Anderson21 suspended admin 115 Rath LLC 16 Mar 2025 15:02:06 PDT 12
Tonya_Mertz73 suspended moderator 7 Denesik - Reichel 11 Jul 2025 11:47:23 PDT 17
Yolanda_Moen suspended admin 117 Labadie, Nienow and Keebler 17 Mar 2025 22:26:30 PDT 2
Cletus_Bergstrom suspended admin 118 Beier, Hintz and Wilderman 13 Oct 2025 06:28:09 PDT 17
Joanna_Oberbrunner77 pending user 118 Renner and Sons 09 Aug 2025 23:48:33 PDT 60
Tianna.Heathcote suspended moderator 116 Denesik - Gottlieb 28 Oct 2025 22:00:47 PDT 23
Amalia.Shields39 pending moderator 101 Schimmel - Stark 13 Jul 2025 07:12:55 PDT 17
Cheyanne_Nader active moderator 117 Zboncak, Abbott and Gerlach 26 Jul 2025 13:21:58 PDT 2
Jasmin.Jerde pending user 119 Bartoletti, Medhurst and Bahringer 13 Jan 2024 22:16:45 PDT 59
Lewis_Torphy suspended admin 119 Hayes and Sons 01 Jan 2025 18:59:04 PDT 31
import {Component} from "@angular/core"
import {LucideCombine, LucideUngroup} from "@lucide/angular"

import {provideIcons} from "@qualcomm-ui/angular-core/lucide"
import {PaginationModule} from "@qualcomm-ui/angular/pagination"
import {
  type AngularTable,
  createAngularTable,
  createTablePagination,
  TableModule,
} from "@qualcomm-ui/angular/table"
import {
  getCoreRowModel,
  getExpandedRowModel,
  getGroupedRowModel,
  getPaginationRowModel,
} from "@qualcomm-ui/core/table"

import {createUserQuery, type User, userColumns} from "./data"

@Component({
  imports: [TableModule, PaginationModule],
  providers: [provideIcons({LucideCombine, LucideUngroup})],
  selector: "grouping-demo",
  template: `
    <div q-table-root>
      <div q-table-scroll-container>
        <table q-table-table>
          <thead q-table-header>
            @for (
              headerGroup of table.getHeaderGroups();
              track headerGroup.id
            ) {
              <tr q-table-row>
                @for (header of headerGroup.headers; track header.id) {
                  <th q-table-header-cell>
                    @if (!header.isPlaceholder) {
                      <div class="flex items-center gap-1">
                        @if (header.column.getCanGroup()) {
                          <button
                            q-table-column-header-action
                            [icon]="
                              header.column.getIsGrouped()
                                ? 'Ungroup'
                                : 'Combine'
                            "
                            (click)="header.column.toggleGrouping()"
                          ></button>
                        }
                        <ng-container *renderHeader="header; let value">
                          {{ value }}
                        </ng-container>
                      </div>
                    }
                  </th>
                }
              </tr>
            }
          </thead>
          <tbody q-table-body>
            @for (row of table.getRowModel().rows; track row.id) {
              <tr q-table-row>
                @for (cell of row.getVisibleCells(); track cell.id) {
                  <td q-table-cell>
                    @if (cell.getIsGrouped()) {
                      <!-- If it's a grouped cell, add an expander and row count -->
                      <div class="inline-flex items-center gap-2">
                        @if (row.getCanExpand()) {
                          <button
                            q-table-row-expand-button
                            [isExpanded]="row.getIsExpanded()"
                            [row]="row"
                          ></button>
                        }
                      </div>
                    }
                    <ng-container
                      *renderCell="
                        cell;
                        isAggregated: cell.getIsAggregated();
                        let value
                      "
                    >
                      {{ value }}
                    </ng-container>
                  </td>
                }
              </tr>
            }
          </tbody>
        </table>
      </div>
      <div
        q-table-pagination
        [count]="pagination.count()"
        [page]="pagination.page()"
        [pageSize]="pagination.pageSize()"
        (pageChanged)="pagination.onPageChange($event)"
      >
        <div *paginationContext="let context" q-pagination-page-metadata>
          @let meta = context.pageMetadata;
          {{ meta.pageStart }}-{{ meta.pageEnd }} of {{ meta.count }} results
        </div>

        <div q-pagination-page-buttons></div>
      </div>
    </div>
  `,
})
export class GroupingDemo {
  protected readonly query = createUserQuery(1000)

  protected table: AngularTable<User> = createAngularTable(() => ({
    columns: userColumns,
    data: this.query.data() || [],
    getCoreRowModel: getCoreRowModel(),
    getExpandedRowModel: getExpandedRowModel(),
    getGroupedRowModel: this.query.data()?.length
      ? getGroupedRowModel()
      : undefined,
    getPaginationRowModel: getPaginationRowModel(),
  }))

  protected pagination = createTablePagination(this.table)
}
Updated by Ryan Bower