📄 tanstack/table/latest/docs/framework/angular/examples/column-pinning-sticky

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

Source: https://tanstack.com/table/latest/docs/framework/angular/examples/column-pinning-sticky



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

Latest

Search...

+ K

Menu

Getting Started

Core Guides

Feature Guides

Core APIs

Feature APIs

Enterprise

Examples

Framework

Angular logo

Angular

Version

Latest

Menu

Getting Started

Core Guides

Feature Guides

Core APIs

Feature APIs

Enterprise

Examples

Angular Example: Column Pinning Sticky

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

      • makeData.ts file iconmakeData.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,
  signal,
} from '@angular/core'
import {
  Column,
  ColumnDef,
  type ColumnOrderState,
  type ColumnPinningState,
  createAngularTable,
  FlexRenderDirective,
  getCoreRowModel,
  type VisibilityState,
} from '@tanstack/angular-table'
import { makeData } from './makeData'
import { faker } from '@faker-js/faker'
import { NgStyle, NgTemplateOutlet, SlicePipe } from '@angular/common'

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

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

@Component({
  selector: 'app-root',
  standalone: true,
  imports: [FlexRenderDirective, SlicePipe, NgTemplateOutlet, NgStyle],
  templateUrl: './app.component.html',
})
export class AppComponent {
  readonly columns = signal([...defaultColumns])
  readonly data = signal<Person[]>(makeData(30))
  readonly columnVisibility = signal<VisibilityState>({})
  readonly columnOrder = signal<ColumnOrderState>([])
  readonly columnPinning = signal<ColumnPinningState>({})
  readonly split = signal(false)

  table = createAngularTable(() => ({
    data: this.data(),
    columns: this.columns(),
    getCoreRowModel: getCoreRowModel(),
    debugTable: true,
    debugHeaders: true,
    debugColumns: true,
    columnResizeMode: 'onChange',
  }))

  stringifiedColumnPinning = computed(() => {
    return JSON.stringify(this.table.getState().columnPinning)
  })

  readonly getCommonPinningStyles = (
    column: Column<Person>
  ): Record<string, any> => {
    const isPinned = column.getIsPinned()
    const isLastLeftPinnedColumn =
      isPinned === 'left' && column.getIsLastColumn('left')
    const isFirstRightPinnedColumn =
      isPinned === 'right' && column.getIsFirstColumn('right')

    return {
      boxShadow: isLastLeftPinnedColumn
        ? '-4px 0 4px -4px gray inset'
        : isFirstRightPinnedColumn
          ? '4px 0 4px -4px gray inset'
          : undefined,
      left: isPinned === 'left' ? `${column.getStart('left')}px` : undefined,
      right: isPinned === 'right' ? `${column.getAfter('right')}px` : undefined,
      opacity: isPinned ? 0.95 : 1,
      position: isPinned ? 'sticky' : 'relative',
      width: `${column.getSize()}px`,
      zIndex: isPinned ? 1 : 0,
    }
  }

  randomizeColumns() {
    this.table.setColumnOrder(
      faker.helpers.shuffle(this.table.getAllLeafColumns().map(d => d.id))
    )
  }

  rerender() {
    this.data.set(makeData(5000))
  }
}


import {
  ChangeDetectionStrategy,
  Component,
  computed,
  signal,
} from '@angular/core'
import {
  Column,
  ColumnDef,
  type ColumnOrderState,
  type ColumnPinningState,
  createAngularTable,
  FlexRenderDirective,
  getCoreRowModel,
  type VisibilityState,
} from '@tanstack/angular-table'
import { makeData } from './makeData'
import { faker } from '@faker-js/faker'
import { NgStyle, NgTemplateOutlet, SlicePipe } from '@angular/common'

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

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

@Component({
  selector: 'app-root',
  standalone: true,
  imports: [FlexRenderDirective, SlicePipe, NgTemplateOutlet, NgStyle],
  templateUrl: './app.component.html',
})
export class AppComponent {
  readonly columns = signal([...defaultColumns])
  readonly data = signal<Person[]>(makeData(30))
  readonly columnVisibility = signal<VisibilityState>({})
  readonly columnOrder = signal<ColumnOrderState>([])
  readonly columnPinning = signal<ColumnPinningState>({})
  readonly split = signal(false)

  table = createAngularTable(() => ({
    data: this.data(),
    columns: this.columns(),
    getCoreRowModel: getCoreRowModel(),
    debugTable: true,
    debugHeaders: true,
    debugColumns: true,
    columnResizeMode: 'onChange',
  }))

  stringifiedColumnPinning = computed(() => {
    return JSON.stringify(this.table.getState().columnPinning)
  })

  readonly getCommonPinningStyles = (
    column: Column<Person>
  ): Record<string, any> => {
    const isPinned = column.getIsPinned()
    const isLastLeftPinnedColumn =
      isPinned === 'left' && column.getIsLastColumn('left')
    const isFirstRightPinnedColumn =
      isPinned === 'right' && column.getIsFirstColumn('right')

    return {
      boxShadow: isLastLeftPinnedColumn
        ? '-4px 0 4px -4px gray inset'
        : isFirstRightPinnedColumn
          ? '4px 0 4px -4px gray inset'
          : undefined,
      left: isPinned === 'left' ? `${column.getStart('left')}px` : undefined,
      right: isPinned === 'right' ? `${column.getAfter('right')}px` : undefined,
      opacity: isPinned ? 0.95 : 1,
      position: isPinned ? 'sticky' : 'relative',
      width: `${column.getSize()}px`,
      zIndex: isPinned ? 1 : 0,
    }
  }

  randomizeColumns() {
    this.table.setColumnOrder(
      faker.helpers.shuffle(this.table.getAllLeafColumns().map(d => d.id))
    )
  }

  rerender() {
    this.data.set(makeData(5000))
  }
}

Column Pinning

Column Visibility

Partners Become a Partner

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

scarf analytics