📄 tanstack/table/latest/docs/framework/angular/examples/row-dnd

File: row-dnd.md | Updated: 11/15/2025

Source: https://tanstack.com/table/latest/docs/framework/angular/examples/row-dnd



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: Row Dnd

Github StackBlitz CodeSandbox

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

Code ExplorerCode

Interactive SandboxSandbox

  • .devcontainer

  • src

    • app

      • app.component.css file iconapp.component.css

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

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

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

      • drag-handle-cell.ts file icondrag-handle-cell.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 {
  ColumnDef,
  createAngularTable,
  flexRenderComponent,
  FlexRenderDirective,
  getCoreRowModel,
  getFilteredRowModel,
  getPaginationRowModel,
} from '@tanstack/angular-table'
import { DragHandleCell } from './drag-handle-cell'
import { makeData, type Person } from './makeData'
import {
  CdkDrag,
  type CdkDragDrop,
  CdkDropList,
  moveItemInArray,
} from '@angular/cdk/drag-drop'
import { JsonPipe } from '@angular/common'

const defaultColumns: ColumnDef<Person>[] = [\
  {\
    id: 'drag-handle',\
    header: 'Move',\
    cell: () => flexRenderComponent(DragHandleCell),\
    size: 60,\
  },\
  {\
    accessorKey: 'firstName',\
    cell: info => info.getValue(),\
  },\
  {\
    accessorFn: row => row.lastName,\
    id: 'lastName',\
    cell: info => info.getValue(),\
    header: () => `Last Name`,\
  },\
  {\
    accessorKey: 'age',\
    header: () => 'Age',\
  },\
  {\
    accessorKey: 'visits',\
    header: () => `Visits`,\
  },\
  {\
    accessorKey: 'status',\
    header: 'Status',\
  },\
  {\
    accessorKey: 'progress',\
    header: 'Profile Progress',\
  },\
]

@Component({
  selector: 'app-root',
  standalone: true,
  imports: [FlexRenderDirective, CdkDropList, CdkDrag, JsonPipe],
  templateUrl: './app.component.html',
  styleUrl: './app.component.css',
  changeDetection: ChangeDetectionStrategy.OnPush,
})
export class AppComponent {
  readonly data = signal<Person[]>(makeData(20))

  readonly table = createAngularTable(() => {
    return {
      data: this.data(),
      columns: defaultColumns,
      getRowId: row => row.userId, //required because row indexes will change
      debugTable: true,
      debugHeaders: true,
      debugColumns: true,
      getCoreRowModel: getCoreRowModel(),
      getFilteredRowModel: getFilteredRowModel(),
      getPaginationRowModel: getPaginationRowModel(),
    }
  })

  readonly sortedIds = computed(() => this.data().map(data => data.userId))

  drop(event: CdkDragDrop<Person[]>) {
    const data = [...this.data()]
    moveItemInArray(data, event.previousIndex, event.currentIndex)
    this.data.set(data)
  }
}


import {
  ChangeDetectionStrategy,
  Component,
  computed,
  signal,
} from '@angular/core'
import {
  ColumnDef,
  createAngularTable,
  flexRenderComponent,
  FlexRenderDirective,
  getCoreRowModel,
  getFilteredRowModel,
  getPaginationRowModel,
} from '@tanstack/angular-table'
import { DragHandleCell } from './drag-handle-cell'
import { makeData, type Person } from './makeData'
import {
  CdkDrag,
  type CdkDragDrop,
  CdkDropList,
  moveItemInArray,
} from '@angular/cdk/drag-drop'
import { JsonPipe } from '@angular/common'

const defaultColumns: ColumnDef<Person>[] = [\
  {\
    id: 'drag-handle',\
    header: 'Move',\
    cell: () => flexRenderComponent(DragHandleCell),\
    size: 60,\
  },\
  {\
    accessorKey: 'firstName',\
    cell: info => info.getValue(),\
  },\
  {\
    accessorFn: row => row.lastName,\
    id: 'lastName',\
    cell: info => info.getValue(),\
    header: () => `Last Name`,\
  },\
  {\
    accessorKey: 'age',\
    header: () => 'Age',\
  },\
  {\
    accessorKey: 'visits',\
    header: () => `Visits`,\
  },\
  {\
    accessorKey: 'status',\
    header: 'Status',\
  },\
  {\
    accessorKey: 'progress',\
    header: 'Profile Progress',\
  },\
]

@Component({
  selector: 'app-root',
  standalone: true,
  imports: [FlexRenderDirective, CdkDropList, CdkDrag, JsonPipe],
  templateUrl: './app.component.html',
  styleUrl: './app.component.css',
  changeDetection: ChangeDetectionStrategy.OnPush,
})
export class AppComponent {
  readonly data = signal<Person[]>(makeData(20))

  readonly table = createAngularTable(() => {
    return {
      data: this.data(),
      columns: defaultColumns,
      getRowId: row => row.userId, //required because row indexes will change
      debugTable: true,
      debugHeaders: true,
      debugColumns: true,
      getCoreRowModel: getCoreRowModel(),
      getFilteredRowModel: getFilteredRowModel(),
      getPaginationRowModel: getPaginationRowModel(),
    }
  })

  readonly sortedIds = computed(() => this.data().map(data => data.userId))

  drop(event: CdkDragDrop<Person[]>) {
    const data = [...this.data()]
    moveItemInArray(data, event.previousIndex, event.currentIndex)
    this.data.set(data)
  }
}

Editable data

Performant Column Resizing

Partners Become a Partner

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

scarf analytics