Column Visibility
Use the columnVisibility state and onColumnVisibilityChange callback to control which columns are visible. The table instance provides methods like toggleAllColumnsVisible() and getAllLeafColumns() for building column picker interfaces.
{
"columnVisibility": {}
}| Username | Account Status | Role | Avg Session Duration | Company Name | Last Visited At | Visit Count |
|---|---|---|---|---|---|---|
| Claudine.Moore11 | active | admin | 85 | Crona - Jerde | 15 Aug 2025 16:38:22 PDT | 2 |
| Julien.Walter89 | active | user | 109 | Bechtelar - Frami | 19 Oct 2025 18:36:01 PDT | 325 |
| Stone_Rowe49 | pending | admin | 119 | Ernser Inc | 02 Sep 2025 04:40:12 PDT | 6 |
| Zachariah_Kassulke | suspended | moderator | 116 | Collins - Mills | 14 Jan 2025 03:14:25 PDT | 232 |
| Charlie.Sporer13 | suspended | admin | 119 | Kuphal Inc | 05 Jun 2025 21:15:17 PDT | 3 |
import {JsonPipe} from "@angular/common"
import {Component, computed, signal} from "@angular/core"
import {FormsModule} from "@angular/forms"
import {CheckboxModule} from "@qualcomm-ui/angular/checkbox"
import {
type AngularTable,
createAngularTable,
TableModule,
} from "@qualcomm-ui/angular/table"
import {getCoreRowModel, type VisibilityState} from "@qualcomm-ui/core/table"
import {createUserQuery, type User, userColumns} from "./data"
@Component({
imports: [TableModule, CheckboxModule, JsonPipe, FormsModule],
selector: "column-visibility-demo",
template: `
<div class="flex w-full flex-col gap-4 p-2">
<div class="flex gap-4">
<div
class="border-neutral-01 inline-flex flex-col gap-1 rounded border p-2"
>
<label
q-checkbox
size="sm"
[ngModel]="table().getIsAllColumnsVisible()"
(ngModelChange)="onToggleAllColumns($event)"
>
<span class="q-body-s strong" q-checkbox-label>Toggle All</span>
</label>
@for (column of table().getAllLeafColumns(); track column.id) {
<label
q-checkbox
size="sm"
[ngModel]="column.getIsVisible()"
(ngModelChange)="onToggleColumn(column.id, $event)"
>
<span q-checkbox-label>{{ column.id }}</span>
</label>
}
</div>
<pre
class="font-code-sm border-neutral-01 w-fit overflow-auto rounded border p-4"
>{{ tableState() | json }}</pre>
</div>
<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 [colSpan]="header.colSpan">
@if (!header.isPlaceholder) {
<ng-container *renderHeader="header; let value">
{{ value }}
</ng-container>
}
</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>
<ng-container *renderCell="cell; let value">
{{ value }}
</ng-container>
</td>
}
</tr>
}
</tbody>
</table>
</div>
</div>
</div>
`,
})
export class ColumnVisibilityDemo {
protected readonly query = createUserQuery(5)
protected readonly columnVisibility = signal<VisibilityState>({})
protected readonly table = computed<AngularTable<User>>(() =>
createAngularTable(() => ({
columns: userColumns,
data: this.query.data() || [],
getCoreRowModel: getCoreRowModel(),
onColumnVisibilityChange: (updater) => {
const newValue =
typeof updater === "function"
? updater(this.columnVisibility())
: updater
this.columnVisibility.set(newValue)
},
state: {
columnVisibility: this.columnVisibility(),
},
})),
)
protected readonly tableState = computed(() => ({
columnVisibility: this.table().getState().columnVisibility,
}))
protected onToggleAllColumns(checked: boolean) {
this.table().toggleAllColumnsVisible(checked)
}
protected onToggleColumn(columnId: string, checked: boolean) {
this.table().getColumn(columnId)?.toggleVisibility(checked)
}
}Updated by Ryan Bower