📄 tanstack/table/v8/docs/framework/angular/examples/column-visibility

File: column-visibility.md | Updated: 11/15/2025

Source: https://tanstack.com/table/v8/docs/framework/angular/examples/column-visibility



TanStack

Table v8v8

Search...

+ K

Auto

Log In

TanStack StartRC

Docs Examples GitHub Contributors

TanStack Router

Docs Examples GitHub Contributors

TanStack Query

Docs Examples GitHub Contributors

TanStack Table

Docs Examples Github Contributors

TanStack Formnew

Docs Examples Github Contributors

TanStack DBbeta

Docs Github Contributors

TanStack Virtual

Docs Examples Github Contributors

TanStack Paceralpha

Docs Examples Github Contributors

TanStack Storealpha

Docs Examples Github Contributors

TanStack Devtoolsalpha

Docs Github Contributors

More Libraries

Maintainers Partners Support Learn StatsBETA Discord Merch Blog GitHub Ethos Brand Guide

Documentation

Framework

Angular logo

Angular

Version

v8

Search...

+ K

Menu

Getting Started

Core Guides

Feature Guides

Core APIs

Feature APIs

Enterprise

Examples

Framework

Angular logo

Angular

Version

v8

Menu

Getting Started

Core Guides

Feature Guides

Core APIs

Feature APIs

Enterprise

Examples

Angular Example: Column Visibility

Github StackBlitz CodeSandbox

===========================================================================================================================================================================================================================================================================================================================================================================================================================================================================

Code ExplorerCode

Interactive SandboxSandbox

  • .devcontainer

  • src

    • app

      • app.component.html file iconapp.component.html

      • app.component.ts file iconapp.component.ts

      • app.config.ts file iconapp.config.ts

    • assets

    • favicon.ico file iconfavicon.ico

    • index.html file iconindex.html

    • main.ts file iconmain.ts

    • styles.scss file iconstyles.scss

  • .editorconfig file icon.editorconfig

  • .gitignore file icon.gitignore

  • README.md file iconREADME.md

  • angular.json file iconangular.json

  • package.json file iconpackage.json

  • tsconfig.app.json file icontsconfig.app.json

  • tsconfig.json file icontsconfig.json

  • tsconfig.spec.json file icontsconfig.spec.json

ts

import {
  ChangeDetectionStrategy,
  Component,
  computed,
  type OnInit,
  signal,
} from '@angular/core'
import {
  ColumnDef,
  createAngularTable,
  FlexRenderDirective,
  getCoreRowModel,
  type VisibilityState,
} from '@tanstack/angular-table'

type Person = {
  firstName: string
  lastName: string
  age: number
  visits: number
  status: string
  progress: number
}

const defaultData: Person[] = [\
  {\
    firstName: 'tanner',\
    lastName: 'linsley',\
    age: 24,\
    visits: 100,\
    status: 'In Relationship',\
    progress: 50,\
  },\
  {\
    firstName: 'tandy',\
    lastName: 'miller',\
    age: 40,\
    visits: 40,\
    status: 'Single',\
    progress: 80,\
  },\
  {\
    firstName: 'joe',\
    lastName: 'dirte',\
    age: 45,\
    visits: 20,\
    status: 'Complicated',\
    progress: 10,\
  },\
]

const defaultColumns: ColumnDef<Person>[] = [\
  {\
    header: 'Name',\
    footer: props => props.column.id,\
    columns: [\
      {\
        accessorKey: 'firstName',\
        cell: info => info.getValue(),\
        footer: props => props.column.id,\
      },\
      {\
        accessorFn: row => row.lastName,\
        id: 'lastName',\
        cell: info => info.getValue(),\
        header: () => 'Last Name',\
        footer: props => props.column.id,\
      },\
    ],\
  },\
  {\
    header: 'Info',\
    footer: props => props.column.id,\
    columns: [\
      {\
        accessorKey: 'age',\
        header: () => 'Age',\
        footer: props => props.column.id,\
      },\
      {\
        header: 'More Info',\
        columns: [\
          {\
            accessorKey: 'visits',\
            header: () => 'Visits',\
            footer: props => props.column.id,\
          },\
          {\
            accessorKey: 'status',\
            header: 'Status',\
            footer: props => props.column.id,\
          },\
          {\
            accessorKey: 'progress',\
            header: 'Profile Progress',\
            footer: props => props.column.id,\
          },\
        ],\
      },\
    ],\
  },\
]

@Component({
  selector: 'app-root',
  standalone: true,
  imports: [FlexRenderDirective],
  templateUrl: './app.component.html',
  changeDetection: ChangeDetectionStrategy.OnPush,
})
export class AppComponent implements OnInit {
  data = signal<Person[]>([])
  readonly columnVisibility = signal<VisibilityState>({})

  table = createAngularTable(() => ({
    data: this.data(),
    columns: defaultColumns,
    state: {
      columnVisibility: this.columnVisibility(),
    },
    getCoreRowModel: getCoreRowModel(),
    onColumnVisibilityChange: updaterOrValue => {
      const visibilityState =
        typeof updaterOrValue === 'function'
          ? updaterOrValue(this.columnVisibility())
          : updaterOrValue
      this.columnVisibility.set(visibilityState)
    },
    debugTable: true,
    debugHeaders: true,
    debugColumns: true,
  }))

  stringifiedColumnVisibility = computed(() => {
    return JSON.stringify(this.table.getState().columnVisibility)
  })

  ngOnInit() {
    this.data.set(defaultData)
  }

  rerender() {
    this.data.set(defaultData)
  }
}


import {
  ChangeDetectionStrategy,
  Component,
  computed,
  type OnInit,
  signal,
} from '@angular/core'
import {
  ColumnDef,
  createAngularTable,
  FlexRenderDirective,
  getCoreRowModel,
  type VisibilityState,
} from '@tanstack/angular-table'

type Person = {
  firstName: string
  lastName: string
  age: number
  visits: number
  status: string
  progress: number
}

const defaultData: Person[] = [\
  {\
    firstName: 'tanner',\
    lastName: 'linsley',\
    age: 24,\
    visits: 100,\
    status: 'In Relationship',\
    progress: 50,\
  },\
  {\
    firstName: 'tandy',\
    lastName: 'miller',\
    age: 40,\
    visits: 40,\
    status: 'Single',\
    progress: 80,\
  },\
  {\
    firstName: 'joe',\
    lastName: 'dirte',\
    age: 45,\
    visits: 20,\
    status: 'Complicated',\
    progress: 10,\
  },\
]

const defaultColumns: ColumnDef<Person>[] = [\
  {\
    header: 'Name',\
    footer: props => props.column.id,\
    columns: [\
      {\
        accessorKey: 'firstName',\
        cell: info => info.getValue(),\
        footer: props => props.column.id,\
      },\
      {\
        accessorFn: row => row.lastName,\
        id: 'lastName',\
        cell: info => info.getValue(),\
        header: () => 'Last Name',\
        footer: props => props.column.id,\
      },\
    ],\
  },\
  {\
    header: 'Info',\
    footer: props => props.column.id,\
    columns: [\
      {\
        accessorKey: 'age',\
        header: () => 'Age',\
        footer: props => props.column.id,\
      },\
      {\
        header: 'More Info',\
        columns: [\
          {\
            accessorKey: 'visits',\
            header: () => 'Visits',\
            footer: props => props.column.id,\
          },\
          {\
            accessorKey: 'status',\
            header: 'Status',\
            footer: props => props.column.id,\
          },\
          {\
            accessorKey: 'progress',\
            header: 'Profile Progress',\
            footer: props => props.column.id,\
          },\
        ],\
      },\
    ],\
  },\
]

@Component({
  selector: 'app-root',
  standalone: true,
  imports: [FlexRenderDirective],
  templateUrl: './app.component.html',
  changeDetection: ChangeDetectionStrategy.OnPush,
})
export class AppComponent implements OnInit {
  data = signal<Person[]>([])
  readonly columnVisibility = signal<VisibilityState>({})

  table = createAngularTable(() => ({
    data: this.data(),
    columns: defaultColumns,
    state: {
      columnVisibility: this.columnVisibility(),
    },
    getCoreRowModel: getCoreRowModel(),
    onColumnVisibilityChange: updaterOrValue => {
      const visibilityState =
        typeof updaterOrValue === 'function'
          ? updaterOrValue(this.columnVisibility())
          : updaterOrValue
      this.columnVisibility.set(visibilityState)
    },
    debugTable: true,
    debugHeaders: true,
    debugColumns: true,
  }))

  stringifiedColumnVisibility = computed(() => {
    return JSON.stringify(this.table.getState().columnVisibility)
  })

  ngOnInit() {
    this.data.set(defaultData)
  }

  rerender() {
    this.data.set(defaultData)
  }
}

Sticky Column Pinning

Column Filters

Partners Become a Partner

Code RabbitCode Rabbit CloudflareCloudflare AG GridAG Grid NetlifyNetlify NeonNeon WorkOSWorkOS ClerkClerk ConvexConvex ElectricElectric SentrySentry PrismaPrisma StrapiStrapi UnkeyUnkey

scarf analytics