Docs
CodeRabbit
Cloudflare
Railway
AG Grid
WorkOS
SerpAPI
OpenRouter
Netlify
Clerk
Unkey
Sentry
Electric
Prisma
CodeRabbit
Cloudflare
Railway
AG Grid
WorkOS
SerpAPI
OpenRouter
Netlify
Clerk
Unkey
Sentry
Electric
Prisma
Table API Reference
Column API Reference
Row API Reference
Cell API Reference
Header API Reference
Features API Reference
Static Functions API Reference
Feature Guides

Virtualization (Angular) Guide

Examples

Want to skip to the implementation? Check out these Angular examples:

Angular Setup

Install and import the Angular virtualizer adapter from @tanstack/angular-virtual. TanStack Table still owns rows, columns, and table state; the virtualizer owns scroll indexes and measurements. Also see the TanStack Virtual table example.

Virtualization (Angular) Guide

The TanStack Table packages do not come with any virtualization APIs or features built in. Virtualization is a rendering strategy, not a table feature. You can use TanStack Table with any virtualization library, but the official examples use TanStack Virtual.

TanStack Table and TanStack Virtual solve different parts of the problem:

  • TanStack Table builds the row models, columns, headers, cells, sizing, sorting, filtering, and other table state.
  • TanStack Virtual decides which item indexes should be rendered for the current scroll position.
  • Your table renderer maps those virtual indexes back to rows, headers, and cells.

When To Use Virtualization

Use virtualization when your table has a very large number of rows, columns, or both. Virtualization keeps the DOM small by only rendering the items that are visible in the scroll viewport plus a small overscan buffer.

Virtualization is not a replacement for server-side pagination, filtering, or sorting. If the data is virtualized on the client, the data still needs to exist on the client. If your dataset is too large to load into the browser, use server-side data operations or infinite scrolling.

For small tables, normal rendering is simpler and usually preferable.

Install TanStack Virtual

Install the Angular virtualizer adapter:

sh
npm install @tanstack/angular-virtual
npm install @tanstack/angular-virtual

The Angular examples use injectVirtualizer from @tanstack/angular-virtual. TanStack Table still owns rows, columns, headers, cells, sizing, sorting, filtering, and other table state; TanStack Virtual decides which item indexes should render for the current scroll position.

The table itself is set up like any other v9 table. Declare your features with tableFeatures() and create the table with injectTable; nothing about virtualization changes the table setup.

ts
import {
  columnSizingFeature,
  rowSortingFeature,
  createSortedRowModel,
  sortFns,
  tableFeatures,
  injectTable,
} from '@tanstack/angular-table'
import { injectVirtualizer } from '@tanstack/angular-virtual'

const features = tableFeatures({
  columnSizingFeature,
  rowSortingFeature,
  sortedRowModel: createSortedRowModel(),
  sortFns,
})

export class App {
  readonly table = injectTable(() => ({
    features,
    columns,
    data: this.data(),
  }))
}
import {
  columnSizingFeature,
  rowSortingFeature,
  createSortedRowModel,
  sortFns,
  tableFeatures,
  injectTable,
} from '@tanstack/angular-table'
import { injectVirtualizer } from '@tanstack/angular-virtual'

const features = tableFeatures({
  columnSizingFeature,
  rowSortingFeature,
  sortedRowModel: createSortedRowModel(),
  sortFns,
})

export class App {
  readonly table = injectTable(() => ({
    features,
    columns,
    data: this.data(),
  }))
}

The Basic Pattern

Most virtualized table implementations follow the same pattern:

  1. Create a fixed-height scroll container.
  2. Pass the scroll element to the virtualizer.
  3. Use table.getRowModel().rows or table.getVisibleLeafColumns() as the source list.
  4. Configure count, estimateSize, overscan, and optional measureElement.
  5. Render only virtual items.
  6. Use virtual offsets or spacer padding to preserve the full scroll geometry.

Here is a compact row virtualization example:

ts
readonly rows = computed(() => this.table.getRowModel().rows)

readonly rowVirtualizer = injectVirtualizer(() => ({
  count: this.rows().length,
  scrollElement: this.scrollContainer()?.nativeElement,
  estimateSize: () => 33,
  overscan: 5,
}))
readonly rows = computed(() => this.table.getRowModel().rows)

readonly rowVirtualizer = injectVirtualizer(() => ({
  count: this.rows().length,
  scrollElement: this.scrollContainer()?.nativeElement,
  estimateSize: () => 33,
  overscan: 5,
}))
html
<tbody [style.height.px]="rowVirtualizer.getTotalSize()" style="position: relative">
  @for (virtualRow of rowVirtualizer.getVirtualItems(); track virtualRow.key) {
    @let row = rows()[virtualRow.index];
    <tr
      [style.position]="'absolute'"
      [style.transform]="'translateY(' + virtualRow.start + 'px)'"
      [style.width]="'100%'"
    >
      @for (cell of row.getVisibleCells(); track cell.id) {
        <td>
          <ng-container *flexRenderCell="cell; let renderCell">
            {{ renderCell }}
          </ng-container>
        </td>
      }
    </tr>
  }
</tbody>
<tbody [style.height.px]="rowVirtualizer.getTotalSize()" style="position: relative">
  @for (virtualRow of rowVirtualizer.getVirtualItems(); track virtualRow.key) {
    @let row = rows()[virtualRow.index];
    <tr
      [style.position]="'absolute'"
      [style.transform]="'translateY(' + virtualRow.start + 'px)'"
      [style.width]="'100%'"
    >
      @for (cell of row.getVisibleCells(); track cell.id) {
        <td>
          <ng-container *flexRenderCell="cell; let renderCell">
            {{ renderCell }}
          </ng-container>
        </td>
      }
    </tr>
  }
</tbody>

Virtualized Rows

The virtualized rows examples show how to render large row counts while keeping the DOM small. The examples are available for React, Solid, Svelte, Vue, Angular, and Lit.

The core idea is that sorting, filtering, grouping, and other row-model work still comes from TanStack Table. The virtualizer reads from the final table row model:

ts
const rows = table.getRowModel().rows
const rows = table.getRowModel().rows

The row virtualizer is configured with count: rows.length, a row height estimate, the scroll container, and an overscan value. The tbody is given the full virtual height with rowVirtualizer.getTotalSize(), while each rendered row is absolutely positioned with transform: translateY(...).

The examples render cells from the current row with APIs like row.getVisibleCells() or row.getAllCells(), depending on whether the example needs visibility-aware cells or all cells.

The official examples use large generated datasets, commonly tens or hundreds of thousands of rows. They also support dynamic row heights by using measureElement when possible. The examples skip dynamic row measurement in Firefox because Firefox can measure table border height differently.

Virtualized Columns

The virtualized columns examples show how to render large row and column counts. The examples are available for React, Solid, Svelte, Vue, Angular, and Lit.

Column virtualization uses the current visible column list:

ts
const visibleColumns = table.getVisibleLeafColumns()
const visibleColumns = table.getVisibleLeafColumns()

The column virtualizer is configured for horizontal virtualization:

ts
readonly visibleColumns = computed(() => this.table.getVisibleLeafColumns())

readonly columnVirtualizer = injectVirtualizer(() => ({
  count: this.visibleColumns().length,
  estimateSize: index => this.visibleColumns()[index].getSize(),
  scrollElement: this.scrollContainer()?.nativeElement,
  horizontal: true,
  overscan: 3,
}))
readonly visibleColumns = computed(() => this.table.getVisibleLeafColumns())

readonly columnVirtualizer = injectVirtualizer(() => ({
  count: this.visibleColumns().length,
  estimateSize: index => this.visibleColumns()[index].getSize(),
  scrollElement: this.scrollContainer()?.nativeElement,
  horizontal: true,
  overscan: 3,
}))

Column virtualization uses a different rendering strategy than row virtualization. Instead of absolutely positioning columns, the examples add fake spacer cells to the left and right:

ts
const virtualColumns = this.columnVirtualizer.getVirtualItems()
const virtualPaddingLeft = virtualColumns[0]?.start ?? 0
const virtualPaddingRight =
  this.columnVirtualizer.getTotalSize() -
  (virtualColumns[virtualColumns.length - 1]?.end ?? 0)
const virtualColumns = this.columnVirtualizer.getVirtualItems()
const virtualPaddingLeft = virtualColumns[0]?.start ?? 0
const virtualPaddingRight =
  this.columnVirtualizer.getTotalSize() -
  (virtualColumns[virtualColumns.length - 1]?.end ?? 0)

Those spacer cells preserve the horizontal scroll width while the renderer only mounts the virtual columns. This approach keeps row rendering table-like and allows dynamic row height measurement to keep working.

Virtualized Rows And Columns Together

The official virtualized columns examples also virtualize rows. In those examples:

  • The row virtualizer controls vertical positioning and total body height.
  • The column virtualizer controls horizontal header/cell rendering and left/right spacer cells.
  • virtualRow.index maps to rows[virtualRow.index].
  • virtualColumn.index maps to visibleCells[virtualColumn.index].

Always use virtual indexes against the same current row and column lists returned by the table. If sorting, filtering, pagination, grouping, or column visibility changes, recompute the virtualized rows and columns from the current table state.

Virtualized Infinite Scrolling

The virtualized infinite scrolling examples combine row virtualization with progressive data fetching. The examples are available for React, Solid, Svelte, Vue, Angular, and Lit.

The common pattern is:

  1. Fetch a page of rows.
  2. Flatten fetched pages into the table data.
  3. Use row virtualization over the loaded rows.
  4. Listen to scroll events on the table container.
  5. Fetch the next page when the user scrolls near the bottom.

The Angular infinite scrolling pattern can use TanStack Query or any other data-fetching layer.

ts
const { scrollHeight, scrollTop, clientHeight } = scrollElement

if (scrollHeight - scrollTop - clientHeight < 500) {
  fetchNextPage()
}
const { scrollHeight, scrollTop, clientHeight } = scrollElement

if (scrollHeight - scrollTop - clientHeight < 500) {
  fetchNextPage()
}

If sorting is handled by the server, use manual sorting so the fetched data reflects the whole backend dataset rather than only the currently loaded rows. When sorting changes and the fetched dataset is replaced, scroll back to the top with rowVirtualizer.scrollToIndex(0).

Dynamic Row Heights

Dynamic row heights are useful when content can wrap or expand. They are also more complex than fixed-height rows.

Use estimateSize as the virtualizer's initial guess:

ts
estimateSize: () => 33
estimateSize: () => 33

Then use measureElement to refine the actual row height after rendering. In Angular, pass a measureElement function to injectVirtualizer and set data-index on each rendered row so the virtualizer can associate measurements with the correct item. This is exactly what the Virtualized Rows example does:

ts
readonly rowVirtualizer = injectVirtualizer(() => ({
  count: this.rows().length,
  scrollElement: this.scrollContainer()?.nativeElement,
  estimateSize: () => 33,
  // measure dynamic row height, except in firefox because it measures table border height incorrectly
  measureElement:
    typeof window !== 'undefined' &&
    navigator.userAgent.indexOf('Firefox') === -1
      ? (element) => element.getBoundingClientRect().height
      : undefined,
  overscan: 5,
}))
readonly rowVirtualizer = injectVirtualizer(() => ({
  count: this.rows().length,
  scrollElement: this.scrollContainer()?.nativeElement,
  estimateSize: () => 33,
  // measure dynamic row height, except in firefox because it measures table border height incorrectly
  measureElement:
    typeof window !== 'undefined' &&
    navigator.userAgent.indexOf('Firefox') === -1
      ? (element) => element.getBoundingClientRect().height
      : undefined,
  overscan: 5,
}))
html
<tr
  [attr.data-index]="virtualRow.index"
  [style.transform]="'translateY(' + virtualRow.start + 'px)'"
>
<tr
  [attr.data-index]="virtualRow.index"
  [style.transform]="'translateY(' + virtualRow.start + 'px)'"
>

Overscan helps avoid blank regions while measurements settle. If every row has a known fixed height, skip dynamic measurement and use the fixed height estimate instead.

Sticky Headers And Semantic Table Markup

The examples still use semantic table tags, but they change table layout CSS to support virtual positioning and sticky headers.

Dynamic row virtualization commonly requires:

css
table {
  display: grid;
}

thead {
  display: grid;
  position: sticky;
  top: 0;
}

tr {
  display: flex;
}
table {
  display: grid;
}

thead {
  display: grid;
  position: sticky;
  top: 0;
}

tr {
  display: flex;
}

Rows are absolutely positioned inside a relatively positioned tbody, and cells use flex sizing so they can match column.getSize() or cell.column.getSize(). This is intentional. Native table layout does not work well with dynamic-height virtual rows that are positioned independently.

Performance Tips

  • Keep virtualizers near the components that render the virtualized items.
  • Avoid re-rendering the full table body on every scroll.
  • Keep row, column, and data references stable where possible.
  • Use overscan deliberately. More overscan reduces visible blanking, while less overscan reduces DOM nodes.
  • Avoid expensive cell renderers in very large virtualized tables.
  • Test production builds. Framework development builds can be slower than production builds; profile production bundles before optimizing.
  • Prefer fixed row sizes when the UI allows it.
  • For column virtualization, use column.getSize(), header.getSize(), and cell.column.getSize() consistently.