data table

Powerful table and datagrids built using TanStack Table.

PreviousNext
StatusAmount
successken99@example.com$316.00
successAbe45@example.com$242.00
processingMonserrat44@example.com$837.00
successSilas22@example.com$874.00
failedcarmella@example.com$721.00
pendinglena.ortiz@example.com$129.00
successomar_h@example.com$563.00
failedjune.park@example.com$98.00
processingtheo.martin@example.com$450.00
successines.costa@example.com$287.00
0 of 12 row(s) selected.
import { ChangeDetectionStrategy, Component, computed, signal } from '@angular/core';

import { NgIcon, provideIcons } from '@ng-icons/core';
import { lucideChevronDown } from '@ng-icons/lucide';
import { createColumnHelper, flexRenderComponent, injectTable } from '@tanstack/angular-table';

import { ZardButtonComponent } from '@/shared/components/button';
import { ZardDataTableImports } from '@/shared/components/data-table';
import { ZardDropdownImports } from '@/shared/components/dropdown';
import { ZardInputComponent } from '@/shared/components/input';

import { features } from './features';
import { type Payment, PAYMENTS } from './payments';
import { PaymentActionsComponent } from './row-actions';
import { SelectAllRowsComponent, SelectRowComponent } from './row-selection';
import { PaymentEmailHeaderComponent } from './sorting';

const currency = new Intl.NumberFormat('en-US', { style: 'currency', currency: 'USD' });

const columnHelper = createColumnHelper<typeof features, Payment>();

const columns = columnHelper.columns([
  columnHelper.display({
    id: 'select',
    header: () => flexRenderComponent(SelectAllRowsComponent),
    cell: () => flexRenderComponent(SelectRowComponent),
    enableSorting: false,
    enableHiding: false,
  }),
  columnHelper.accessor('status', { header: 'Status', meta: { cellClass: 'capitalize' } }),
  columnHelper.accessor('email', {
    header: () => flexRenderComponent(PaymentEmailHeaderComponent),
    meta: { cellClass: 'lowercase' },
  }),
  columnHelper.accessor('amount', {
    header: 'Amount',
    cell: ({ getValue }) => currency.format(getValue()),
    meta: { headerClass: 'text-end', cellClass: 'text-end font-medium' },
  }),
  columnHelper.display({
    id: 'actions',
    cell: () => flexRenderComponent(PaymentActionsComponent),
    enableHiding: false,
  }),
]);

@Component({
  selector: 'z-demo-data-table-preview',
  imports: [ZardDataTableImports, ZardButtonComponent, ZardDropdownImports, ZardInputComponent, NgIcon],
  template: `
    <div class="flex items-center gap-2 py-4">
      <input
        z-input
        class="max-w-sm"
        placeholder="Filter emails..."
        aria-label="Filter emails"
        [value]="emailFilter()"
        (input)="filterEmails($event)"
      />
      <button type="button" z-button zType="outline" class="ms-auto" z-dropdown [zDropdownMenu]="columnsMenu">
        Columns
        <ng-icon name="lucideChevronDown" aria-hidden="true" />
      </button>
      <z-dropdown-menu-content #columnsMenu="zDropdownMenuContent" zAlign="end">
        @for (column of hideableColumns(); track column.id) {
          <z-dropdown-menu-checkbox-item
            class="capitalize"
            [zChecked]="column.getIsVisible()"
            (zCheckedChange)="column.toggleVisibility($event)"
          >
            {{ column.id }}
          </z-dropdown-menu-checkbox-item>
        }
      </z-dropdown-menu-content>
    </div>
    <z-data-table [zTable]="table" />
    <div class="flex items-center justify-end gap-2 py-4">
      <div class="text-muted-foreground flex-1 text-sm">
        {{ table.getFilteredSelectedRowModel().rows.length }} of {{ table.getFilteredRowModel().rows.length }} row(s)
        selected.
      </div>
      <button
        type="button"
        z-button
        zType="outline"
        zSize="sm"
        [zDisabled]="!table.getCanPreviousPage()"
        (click)="table.previousPage()"
      >
        Previous
      </button>
      <button
        type="button"
        z-button
        zType="outline"
        zSize="sm"
        [zDisabled]="!table.getCanNextPage()"
        (click)="table.nextPage()"
      >
        Next
      </button>
    </div>
  `,
  changeDetection: ChangeDetectionStrategy.OnPush,
  viewProviders: [provideIcons({ lucideChevronDown })],
  host: { class: 'block w-full' },
})
export class ZardDemoDataTablePreviewComponent {
  readonly data = signal<Payment[]>(PAYMENTS);

  readonly table = injectTable(() => ({
    features,
    columns,
    data: this.data(),
    getRowId: row => row.id,
  }));

  protected readonly hideableColumns = computed(() => this.table.getAllColumns().filter(column => column.getCanHide()));

  protected readonly emailFilter = computed(() => (this.table.getColumn('email')?.getFilterValue() as string) ?? '');

  protected filterEmails(event: Event): void {
    this.table.getColumn('email')?.setFilterValue((event.target as HTMLInputElement).value);
  }
}
Every data table or datagrid is different: how it sorts, filters and paginates, and where its data comes from. Instead of one component with an option for each of those, this guide shows how to build your own with TanStack Table and Table.
TanStack Table is headless: it holds the state and the logic, and you write the markup. z-data-table is the markup — it renders a TanStack table with z-table — and z-data-table-column-header, z-data-table-pagination and z-data-table-view-options are the parts most tables share. Each of them reads only the features your table declares.

Installation

Copy
npx zard-cli@latest add data-table

Usage

import { injectTable, rowPaginationFeature, tableFeatures } from '@tanstack/angular-table';

import { ZardDataTableImports } from '@/shared/components/data-table/data-table.imports';

const features = tableFeatures({ rowPaginationFeature });
const columns = [
  { accessorKey: 'email', header: 'Email' },
  { accessorKey: 'amount', header: 'Amount' },
];

// In the component class:
readonly table = injectTable(() => ({ features, columns, data: this.data() }));
Copy
<z-data-table [zTable]="table" />
<z-data-table-pagination [zTable]="table" />
Copy

Prerequisites

We are going to build a table to show recent payments. Here is what our data looks like:
export interface Payment {
  id: string;
  amount: number;
  status: 'pending' | 'processing' | 'success' | 'failed';
  email: string;
}

export const PAYMENTS: Payment[] = [
  { id: 'm5gr84i9', amount: 316, status: 'success', email: 'ken99@example.com' },
  { id: '3u1reuv4', amount: 242, status: 'success', email: 'Abe45@example.com' },
  { id: 'derv1ws0', amount: 837, status: 'processing', email: 'Monserrat44@example.com' },
  { id: '5kma53ae', amount: 874, status: 'success', email: 'Silas22@example.com' },
  { id: 'bhqecj4p', amount: 721, status: 'failed', email: 'carmella@example.com' },
  { id: 'p8x2kq7n', amount: 129, status: 'pending', email: 'lena.ortiz@example.com' },
  { id: 'z4m9d1rt', amount: 563, status: 'success', email: 'omar_h@example.com' },
  { id: 'c7v0w2yb', amount: 98, status: 'failed', email: 'june.park@example.com' },
  { id: 'q1n6s8ue', amount: 450, status: 'processing', email: 'theo.martin@example.com' },
  { id: 'h3j5l9fa', amount: 287, status: 'success', email: 'ines.costa@example.com' },
  { id: 'w2e8r4tz', amount: 690, status: 'pending', email: 'noah.b@example.com' },
  { id: 'k9b3x7cm', amount: 145, status: 'success', email: 'maya.lee@example.com' },
];
Copy

Project Structure

Start with one file per concern. The examples below keep each step in a single file so you can read it top to bottom.
src/app/payments
├── payments.ts        # the Payment type and the data
├── features.ts        # tableFeatures(): what the table can do
├── columns.ts         # the column definitions
└── payments-table.ts  # the component: injectTable() + <z-data-table>
Copy

Set up Table Features

TanStack Table v9 is feature-based: you opt into the behavior you want with tableFeatures(). Declare the features once, outside any component, and pass them to every injectTable call. The core row model is always included; the optional ones (createSortedRowModel(), createFilteredRowModel(), …) are registered here too. The columnMeta slot types the column meta that z-data-table reads.
import {
  columnFilteringFeature,
  columnVisibilityFeature,
  createFilteredRowModel,
  createPaginatedRowModel,
  createSortedRowModel,
  filterFn_includesString,
  rowPaginationFeature,
  rowSelectionFeature,
  rowSortingFeature,
  sortFn_alphanumeric,
  sortFn_text,
  tableFeatures,
} from '@tanstack/angular-table';

import type { ZardDataTableColumnMeta } from '@/shared/components/data-table';

export const features = tableFeatures({
  columnFilteringFeature,
  columnVisibilityFeature,
  rowPaginationFeature,
  rowSelectionFeature,
  rowSortingFeature,
  filteredRowModel: createFilteredRowModel(),
  paginatedRowModel: createPaginatedRowModel(),
  sortedRowModel: createSortedRowModel(),
  filterFns: { includesString: filterFn_includesString },
  sortFns: { alphanumeric: sortFn_alphanumeric, text: sortFn_text },
  columnMeta: {} as ZardDataTableColumnMeta,
});

export type DataTableFeatures = typeof features;
Copy

Basic Table

Define the columns with createColumnHelper, create the table with injectTable in a field initializer, and hand it to z-data-table. Keep the features and the columns outside the initializer: only the data should change there.
StatusEmailAmount
successken99@example.com316
successAbe45@example.com242
processingMonserrat44@example.com837
successSilas22@example.com874
failedcarmella@example.com721
pendinglena.ortiz@example.com129
successomar_h@example.com563
failedjune.park@example.com98
processingtheo.martin@example.com450
successines.costa@example.com287
import { ChangeDetectionStrategy, Component, signal } from '@angular/core';

import { createColumnHelper, injectTable } from '@tanstack/angular-table';

import { ZardDataTableImports } from '@/shared/components/data-table';

import { features } from './features';
import { type Payment, PAYMENTS } from './payments';

const columnHelper = createColumnHelper<typeof features, Payment>();

const columns = columnHelper.columns([
  columnHelper.accessor('status', { header: 'Status' }),
  columnHelper.accessor('email', { header: 'Email' }),
  columnHelper.accessor('amount', { header: 'Amount' }),
]);

@Component({
  selector: 'z-demo-data-table-basic',
  imports: [ZardDataTableImports],
  template: `
    <z-data-table [zTable]="table" />
  `,
  changeDetection: ChangeDetectionStrategy.OnPush,
  host: { class: 'block w-full' },
})
export class ZardDemoDataTableBasicComponent {
  readonly data = signal<Payment[]>(PAYMENTS);

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

Cell Formatting

A cell function formats the value. To align the column, set meta.headerClass and meta.cellClass: z-data-table adds them to the column’s th and td.
StatusEmailAmount
successken99@example.com$316.00
successAbe45@example.com$242.00
processingMonserrat44@example.com$837.00
successSilas22@example.com$874.00
failedcarmella@example.com$721.00
pendinglena.ortiz@example.com$129.00
successomar_h@example.com$563.00
failedjune.park@example.com$98.00
processingtheo.martin@example.com$450.00
successines.costa@example.com$287.00
import { ChangeDetectionStrategy, Component, signal } from '@angular/core';

import { createColumnHelper, injectTable } from '@tanstack/angular-table';

import { ZardDataTableImports } from '@/shared/components/data-table';

import { features } from './features';
import { type Payment, PAYMENTS } from './payments';

const currency = new Intl.NumberFormat('en-US', { style: 'currency', currency: 'USD' });

const columnHelper = createColumnHelper<typeof features, Payment>();

const columns = columnHelper.columns([
  columnHelper.accessor('status', { header: 'Status' }),
  columnHelper.accessor('email', { header: 'Email' }),
  columnHelper.accessor('amount', {
    header: 'Amount',
    cell: ({ getValue }) => currency.format(getValue()),
    meta: { headerClass: 'text-end', cellClass: 'text-end font-medium' },
  }),
]);

@Component({
  selector: 'z-demo-data-table-cell-formatting',
  imports: [ZardDataTableImports],
  template: `
    <z-data-table [zTable]="table" />
  `,
  changeDetection: ChangeDetectionStrategy.OnPush,
  host: { class: 'block w-full' },
})
export class ZardDemoDataTableCellFormattingComponent {
  readonly data = signal<Payment[]>(PAYMENTS);

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

Column meta

const features = tableFeatures({
  // …
  columnMeta: {} as ZardDataTableColumnMeta,
});

columnHelper.accessor('amount', {
  header: 'Amount',
  meta: { headerClass: 'text-end', cellClass: 'text-end font-medium' },
}),
Copy

Row Actions

A cell can render a component. Return flexRenderComponent(...) from cell, and read the row inside the component with injectTableCellContext() — row.original is that row’s data, so an action such as a delete call can use its id.
StatusEmailAmount
successken99@example.com$316.00
successAbe45@example.com$242.00
processingMonserrat44@example.com$837.00
successSilas22@example.com$874.00
failedcarmella@example.com$721.00
pendinglena.ortiz@example.com$129.00
successomar_h@example.com$563.00
failedjune.park@example.com$98.00
processingtheo.martin@example.com$450.00
successines.costa@example.com$287.00
import { ChangeDetectionStrategy, Component, signal } from '@angular/core';

import { NgIcon, provideIcons } from '@ng-icons/core';
import { lucideEllipsis } from '@ng-icons/lucide';
import { createColumnHelper, flexRenderComponent, injectTable, injectTableCellContext } from '@tanstack/angular-table';

import { ZardButtonComponent } from '@/shared/components/button';
import { ZardDataTableImports } from '@/shared/components/data-table';
import { ZardDropdownImports } from '@/shared/components/dropdown';

import { type DataTableFeatures, features } from './features';
import { type Payment, PAYMENTS } from './payments';

/** Rendered in the actions column. `row.original` is the payment of that row. */
@Component({
  selector: 'z-demo-payment-actions',
  imports: [ZardButtonComponent, ZardDropdownImports, NgIcon],
  template: `
    <button type="button" z-button zType="ghost" zSize="icon" class="size-8" z-dropdown [zDropdownMenu]="menu">
      <span class="sr-only">Open menu</span>
      <ng-icon name="lucideEllipsis" aria-hidden="true" />
    </button>
    <z-dropdown-menu-content #menu="zDropdownMenuContent" zAlign="end">
      <z-dropdown-menu-label>Actions</z-dropdown-menu-label>
      <z-dropdown-menu-item (click)="copyId()">Copy payment ID</z-dropdown-menu-item>
      <z-dropdown-menu-separator />
      <z-dropdown-menu-item>View customer</z-dropdown-menu-item>
      <z-dropdown-menu-item>View payment details</z-dropdown-menu-item>
    </z-dropdown-menu-content>
  `,
  changeDetection: ChangeDetectionStrategy.OnPush,
  viewProviders: [provideIcons({ lucideEllipsis })],
  host: { class: 'flex justify-end' },
})
export class PaymentActionsComponent {
  private readonly cell = injectTableCellContext<DataTableFeatures, Payment, unknown>();

  protected copyId(): void {
    void navigator.clipboard?.writeText(this.cell().row.original.id);
  }
}

const currency = new Intl.NumberFormat('en-US', { style: 'currency', currency: 'USD' });

const columnHelper = createColumnHelper<typeof features, Payment>();

const columns = columnHelper.columns([
  columnHelper.accessor('status', { header: 'Status' }),
  columnHelper.accessor('email', { header: 'Email' }),
  columnHelper.accessor('amount', {
    header: 'Amount',
    cell: ({ getValue }) => currency.format(getValue()),
    meta: { headerClass: 'text-end', cellClass: 'text-end font-medium' },
  }),
  columnHelper.display({
    id: 'actions',
    cell: () => flexRenderComponent(PaymentActionsComponent),
  }),
]);

@Component({
  selector: 'z-demo-data-table-row-actions',
  imports: [ZardDataTableImports],
  template: `
    <z-data-table [zTable]="table" />
  `,
  changeDetection: ChangeDetectionStrategy.OnPush,
  host: { class: 'block w-full' },
})
export class ZardDemoDataTableRowActionsComponent {
  readonly data = signal<Payment[]>(PAYMENTS);

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

Pagination

Pagination is already on: the features include rowPaginationFeature and createPaginatedRowModel(), so the table splits the rows into pages of 10. Add the controls with table.previousPage() and table.nextPage().
StatusEmailAmount
successken99@example.com$316.00
successAbe45@example.com$242.00
processingMonserrat44@example.com$837.00
successSilas22@example.com$874.00
failedcarmella@example.com$721.00
import { ChangeDetectionStrategy, Component, signal } from '@angular/core';

import { createColumnHelper, flexRenderComponent, injectTable } from '@tanstack/angular-table';

import { ZardButtonComponent } from '@/shared/components/button';
import { ZardDataTableImports } from '@/shared/components/data-table';

import { features } from './features';
import { type Payment, PAYMENTS } from './payments';
import { PaymentActionsComponent } from './row-actions';

const currency = new Intl.NumberFormat('en-US', { style: 'currency', currency: 'USD' });

const columnHelper = createColumnHelper<typeof features, Payment>();

const columns = columnHelper.columns([
  columnHelper.accessor('status', { header: 'Status' }),
  columnHelper.accessor('email', { header: 'Email' }),
  columnHelper.accessor('amount', {
    header: 'Amount',
    cell: ({ getValue }) => currency.format(getValue()),
    meta: { headerClass: 'text-end', cellClass: 'text-end font-medium' },
  }),
  columnHelper.display({ id: 'actions', cell: () => flexRenderComponent(PaymentActionsComponent) }),
]);

@Component({
  selector: 'z-demo-data-table-pagination',
  imports: [ZardDataTableImports, ZardButtonComponent],
  template: `
    <z-data-table [zTable]="table" />
    <div class="flex items-center justify-end gap-2 py-4">
      <button
        type="button"
        z-button
        zType="outline"
        zSize="sm"
        [zDisabled]="!table.getCanPreviousPage()"
        (click)="table.previousPage()"
      >
        Previous
      </button>
      <button
        type="button"
        z-button
        zType="outline"
        zSize="sm"
        [zDisabled]="!table.getCanNextPage()"
        (click)="table.nextPage()"
      >
        Next
      </button>
    </div>
  `,
  changeDetection: ChangeDetectionStrategy.OnPush,
  host: { class: 'block w-full' },
})
export class ZardDemoDataTablePaginationComponent {
  readonly data = signal<Payment[]>(PAYMENTS);

  readonly table = injectTable(() => ({
    features,
    columns,
    data: this.data(),
    // Pages of 10 are the default; 5 makes the second page visible with this short list.
    initialState: { pagination: { pageIndex: 0, pageSize: 5 } },
  }));
}

Sorting

Sorting is on too, through rowSortingFeature. Make a header sortable by rendering a component that reads its column with injectTableHeaderContext() and calls column.toggleSorting().
StatusAmount
successken99@example.com$316.00
successAbe45@example.com$242.00
processingMonserrat44@example.com$837.00
successSilas22@example.com$874.00
failedcarmella@example.com$721.00
import { ChangeDetectionStrategy, Component, signal } from '@angular/core';

import { NgIcon, provideIcons } from '@ng-icons/core';
import { lucideArrowUpDown } from '@ng-icons/lucide';
import {
  createColumnHelper,
  flexRenderComponent,
  injectTable,
  injectTableHeaderContext,
} from '@tanstack/angular-table';

import { ZardButtonComponent } from '@/shared/components/button';
import { ZardDataTableImports } from '@/shared/components/data-table';

import { type DataTableFeatures, features } from './features';
import { type Payment, PAYMENTS } from './payments';
import { PaymentActionsComponent } from './row-actions';

/** Rendered as the email header. Each click flips the sort between ascending and descending. */
@Component({
  selector: 'z-demo-payment-email-header',
  imports: [ZardButtonComponent, NgIcon],
  template: `
    <button type="button" z-button zType="ghost" class="-ms-2.5" (click)="toggle()">
      Email
      <ng-icon name="lucideArrowUpDown" aria-hidden="true" />
    </button>
  `,
  changeDetection: ChangeDetectionStrategy.OnPush,
  viewProviders: [provideIcons({ lucideArrowUpDown })],
})
export class PaymentEmailHeaderComponent {
  private readonly header = injectTableHeaderContext<DataTableFeatures, Payment, unknown>();

  protected toggle(): void {
    const column = this.header().column;
    column.toggleSorting(column.getIsSorted() === 'asc');
  }
}

const currency = new Intl.NumberFormat('en-US', { style: 'currency', currency: 'USD' });

const columnHelper = createColumnHelper<typeof features, Payment>();

const columns = columnHelper.columns([
  columnHelper.accessor('status', { header: 'Status' }),
  columnHelper.accessor('email', { header: () => flexRenderComponent(PaymentEmailHeaderComponent) }),
  columnHelper.accessor('amount', {
    header: 'Amount',
    cell: ({ getValue }) => currency.format(getValue()),
    meta: { headerClass: 'text-end', cellClass: 'text-end font-medium' },
  }),
  columnHelper.display({ id: 'actions', cell: () => flexRenderComponent(PaymentActionsComponent) }),
]);

@Component({
  selector: 'z-demo-data-table-sorting',
  imports: [ZardDataTableImports, ZardButtonComponent],
  template: `
    <z-data-table [zTable]="table" />
    <div class="flex items-center justify-end gap-2 py-4">
      <button
        type="button"
        z-button
        zType="outline"
        zSize="sm"
        [zDisabled]="!table.getCanPreviousPage()"
        (click)="table.previousPage()"
      >
        Previous
      </button>
      <button
        type="button"
        z-button
        zType="outline"
        zSize="sm"
        [zDisabled]="!table.getCanNextPage()"
        (click)="table.nextPage()"
      >
        Next
      </button>
    </div>
  `,
  changeDetection: ChangeDetectionStrategy.OnPush,
  host: { class: 'block w-full' },
})
export class ZardDemoDataTableSortingComponent {
  readonly data = signal<Payment[]>(PAYMENTS);

  readonly table = injectTable(() => ({
    features,
    columns,
    data: this.data(),
    initialState: { pagination: { pageIndex: 0, pageSize: 5 } },
  }));
}

Filtering

With columnFilteringFeature in the features, filter a column with column.setFilterValue(). Here an input filters the emails.
StatusAmount
successken99@example.com$316.00
successAbe45@example.com$242.00
processingMonserrat44@example.com$837.00
successSilas22@example.com$874.00
failedcarmella@example.com$721.00
import { ChangeDetectionStrategy, Component, computed, signal } from '@angular/core';

import { createColumnHelper, flexRenderComponent, injectTable } from '@tanstack/angular-table';

import { ZardButtonComponent } from '@/shared/components/button';
import { ZardDataTableImports } from '@/shared/components/data-table';
import { ZardInputComponent } from '@/shared/components/input';

import { features } from './features';
import { type Payment, PAYMENTS } from './payments';
import { PaymentActionsComponent } from './row-actions';
import { PaymentEmailHeaderComponent } from './sorting';

const currency = new Intl.NumberFormat('en-US', { style: 'currency', currency: 'USD' });

const columnHelper = createColumnHelper<typeof features, Payment>();

const columns = columnHelper.columns([
  columnHelper.accessor('status', { header: 'Status' }),
  columnHelper.accessor('email', { header: () => flexRenderComponent(PaymentEmailHeaderComponent) }),
  columnHelper.accessor('amount', {
    header: 'Amount',
    cell: ({ getValue }) => currency.format(getValue()),
    meta: { headerClass: 'text-end', cellClass: 'text-end font-medium' },
  }),
  columnHelper.display({ id: 'actions', cell: () => flexRenderComponent(PaymentActionsComponent) }),
]);

@Component({
  selector: 'z-demo-data-table-filtering',
  imports: [ZardDataTableImports, ZardButtonComponent, ZardInputComponent],
  template: `
    <div class="flex items-center py-4">
      <input
        z-input
        class="max-w-sm"
        placeholder="Filter emails..."
        aria-label="Filter emails"
        [value]="emailFilter()"
        (input)="filterEmails($event)"
      />
    </div>
    <z-data-table [zTable]="table" />
    <div class="flex items-center justify-end gap-2 py-4">
      <button
        type="button"
        z-button
        zType="outline"
        zSize="sm"
        [zDisabled]="!table.getCanPreviousPage()"
        (click)="table.previousPage()"
      >
        Previous
      </button>
      <button
        type="button"
        z-button
        zType="outline"
        zSize="sm"
        [zDisabled]="!table.getCanNextPage()"
        (click)="table.nextPage()"
      >
        Next
      </button>
    </div>
  `,
  changeDetection: ChangeDetectionStrategy.OnPush,
  host: { class: 'block w-full' },
})
export class ZardDemoDataTableFilteringComponent {
  readonly data = signal<Payment[]>(PAYMENTS);

  readonly table = injectTable(() => ({
    features,
    columns,
    data: this.data(),
    initialState: { pagination: { pageIndex: 0, pageSize: 5 } },
  }));

  protected readonly emailFilter = computed(() => (this.table.getColumn('email')?.getFilterValue() as string) ?? '');

  protected filterEmails(event: Event): void {
    this.table.getColumn('email')?.setFilterValue((event.target as HTMLInputElement).value);
  }
}

Visibility

Columns can be hidden with column.toggleVisibility(). This adds a dropdown menu that toggles the columns; enableHiding: false keeps a column out of it.
StatusAmount
successken99@example.com$316.00
successAbe45@example.com$242.00
processingMonserrat44@example.com$837.00
successSilas22@example.com$874.00
failedcarmella@example.com$721.00
import { ChangeDetectionStrategy, Component, computed, signal } from '@angular/core';

import { NgIcon, provideIcons } from '@ng-icons/core';
import { lucideChevronDown } from '@ng-icons/lucide';
import { createColumnHelper, flexRenderComponent, injectTable } from '@tanstack/angular-table';

import { ZardButtonComponent } from '@/shared/components/button';
import { ZardDataTableImports } from '@/shared/components/data-table';
import { ZardDropdownImports } from '@/shared/components/dropdown';
import { ZardInputComponent } from '@/shared/components/input';

import { features } from './features';
import { type Payment, PAYMENTS } from './payments';
import { PaymentActionsComponent } from './row-actions';
import { PaymentEmailHeaderComponent } from './sorting';

const currency = new Intl.NumberFormat('en-US', { style: 'currency', currency: 'USD' });

const columnHelper = createColumnHelper<typeof features, Payment>();

const columns = columnHelper.columns([
  columnHelper.accessor('status', { header: 'Status' }),
  columnHelper.accessor('email', { header: () => flexRenderComponent(PaymentEmailHeaderComponent) }),
  columnHelper.accessor('amount', {
    header: 'Amount',
    cell: ({ getValue }) => currency.format(getValue()),
    meta: { headerClass: 'text-end', cellClass: 'text-end font-medium' },
  }),
  columnHelper.display({
    id: 'actions',
    cell: () => flexRenderComponent(PaymentActionsComponent),
    enableHiding: false,
  }),
]);

@Component({
  selector: 'z-demo-data-table-visibility',
  imports: [ZardDataTableImports, ZardButtonComponent, ZardDropdownImports, ZardInputComponent, NgIcon],
  template: `
    <div class="flex items-center gap-2 py-4">
      <input
        z-input
        class="max-w-sm"
        placeholder="Filter emails..."
        aria-label="Filter emails"
        [value]="emailFilter()"
        (input)="filterEmails($event)"
      />
      <button type="button" z-button zType="outline" class="ms-auto" z-dropdown [zDropdownMenu]="columnsMenu">
        Columns
        <ng-icon name="lucideChevronDown" aria-hidden="true" />
      </button>
      <z-dropdown-menu-content #columnsMenu="zDropdownMenuContent" zAlign="end">
        @for (column of hideableColumns(); track column.id) {
          <z-dropdown-menu-checkbox-item
            class="capitalize"
            [zChecked]="column.getIsVisible()"
            (zCheckedChange)="column.toggleVisibility($event)"
          >
            {{ column.id }}
          </z-dropdown-menu-checkbox-item>
        }
      </z-dropdown-menu-content>
    </div>
    <z-data-table [zTable]="table" />
    <div class="flex items-center justify-end gap-2 py-4">
      <button
        type="button"
        z-button
        zType="outline"
        zSize="sm"
        [zDisabled]="!table.getCanPreviousPage()"
        (click)="table.previousPage()"
      >
        Previous
      </button>
      <button
        type="button"
        z-button
        zType="outline"
        zSize="sm"
        [zDisabled]="!table.getCanNextPage()"
        (click)="table.nextPage()"
      >
        Next
      </button>
    </div>
  `,
  changeDetection: ChangeDetectionStrategy.OnPush,
  viewProviders: [provideIcons({ lucideChevronDown })],
  host: { class: 'block w-full' },
})
export class ZardDemoDataTableVisibilityComponent {
  readonly data = signal<Payment[]>(PAYMENTS);

  readonly table = injectTable(() => ({
    features,
    columns,
    data: this.data(),
    initialState: { pagination: { pageIndex: 0, pageSize: 5 } },
  }));

  protected readonly hideableColumns = computed(() => this.table.getAllColumns().filter(column => column.getCanHide()));

  protected readonly emailFilter = computed(() => (this.table.getColumn('email')?.getFilterValue() as string) ?? '');

  protected filterEmails(event: Event): void {
    this.table.getColumn('email')?.setFilterValue((event.target as HTMLInputElement).value);
  }
}

Row Selection

Add a select column with a checkbox in the header that selects the whole page, and one in each row. table.getFilteredSelectedRowModel() gives the selected rows, which z-data-table also marks with data-state="selected".
StatusAmount
successken99@example.com$316.00
successAbe45@example.com$242.00
processingMonserrat44@example.com$837.00
successSilas22@example.com$874.00
failedcarmella@example.com$721.00
0 of 12 row(s) selected.
import { ChangeDetectionStrategy, Component, computed, signal } from '@angular/core';
import { FormsModule } from '@angular/forms';

import { NgIcon, provideIcons } from '@ng-icons/core';
import { lucideChevronDown } from '@ng-icons/lucide';
import {
  createColumnHelper,
  flexRenderComponent,
  injectTable,
  injectTableCellContext,
  injectTableContext,
} from '@tanstack/angular-table';

import { ZardButtonComponent } from '@/shared/components/button';
import { ZardCheckboxComponent } from '@/shared/components/checkbox';
import { ZardDataTableImports } from '@/shared/components/data-table';
import { ZardDropdownImports } from '@/shared/components/dropdown';
import { ZardInputComponent } from '@/shared/components/input';

import { type DataTableFeatures, features } from './features';
import { type Payment, PAYMENTS } from './payments';
import { PaymentActionsComponent } from './row-actions';
import { PaymentEmailHeaderComponent } from './sorting';

/** Header checkbox: selects or clears every row of the current page. */
@Component({
  selector: 'z-demo-select-all-rows',
  imports: [ZardCheckboxComponent, FormsModule],
  template: `
    <z-checkbox
      [ngModel]="table().getIsAllPageRowsSelected()"
      (ngModelChange)="table().toggleAllPageRowsSelected($event)"
    >
      <span class="sr-only">Select all</span>
    </z-checkbox>
  `,
  changeDetection: ChangeDetectionStrategy.OnPush,
})
export class SelectAllRowsComponent {
  protected readonly table = injectTableContext<DataTableFeatures, Payment>();
}

/** Row checkbox. */
@Component({
  selector: 'z-demo-select-row',
  imports: [ZardCheckboxComponent, FormsModule],
  template: `
    <z-checkbox [ngModel]="cell().row.getIsSelected()" (ngModelChange)="cell().row.toggleSelected($event)">
      <span class="sr-only">Select row</span>
    </z-checkbox>
  `,
  changeDetection: ChangeDetectionStrategy.OnPush,
})
export class SelectRowComponent {
  protected readonly cell = injectTableCellContext<DataTableFeatures, Payment, unknown>();
}

const currency = new Intl.NumberFormat('en-US', { style: 'currency', currency: 'USD' });

const columnHelper = createColumnHelper<typeof features, Payment>();

const columns = columnHelper.columns([
  columnHelper.display({
    id: 'select',
    header: () => flexRenderComponent(SelectAllRowsComponent),
    cell: () => flexRenderComponent(SelectRowComponent),
    enableSorting: false,
    enableHiding: false,
  }),
  columnHelper.accessor('status', { header: 'Status' }),
  columnHelper.accessor('email', { header: () => flexRenderComponent(PaymentEmailHeaderComponent) }),
  columnHelper.accessor('amount', {
    header: 'Amount',
    cell: ({ getValue }) => currency.format(getValue()),
    meta: { headerClass: 'text-end', cellClass: 'text-end font-medium' },
  }),
  columnHelper.display({
    id: 'actions',
    cell: () => flexRenderComponent(PaymentActionsComponent),
    enableHiding: false,
  }),
]);

@Component({
  selector: 'z-demo-data-table-row-selection',
  imports: [ZardDataTableImports, ZardButtonComponent, ZardDropdownImports, ZardInputComponent, NgIcon],
  template: `
    <div class="flex items-center gap-2 py-4">
      <input
        z-input
        class="max-w-sm"
        placeholder="Filter emails..."
        aria-label="Filter emails"
        [value]="emailFilter()"
        (input)="filterEmails($event)"
      />
      <button type="button" z-button zType="outline" class="ms-auto" z-dropdown [zDropdownMenu]="columnsMenu">
        Columns
        <ng-icon name="lucideChevronDown" aria-hidden="true" />
      </button>
      <z-dropdown-menu-content #columnsMenu="zDropdownMenuContent" zAlign="end">
        @for (column of hideableColumns(); track column.id) {
          <z-dropdown-menu-checkbox-item
            class="capitalize"
            [zChecked]="column.getIsVisible()"
            (zCheckedChange)="column.toggleVisibility($event)"
          >
            {{ column.id }}
          </z-dropdown-menu-checkbox-item>
        }
      </z-dropdown-menu-content>
    </div>
    <z-data-table [zTable]="table" />
    <div class="flex items-center justify-end gap-2 py-4">
      <div class="text-muted-foreground flex-1 text-sm">
        {{ table.getFilteredSelectedRowModel().rows.length }} of {{ table.getFilteredRowModel().rows.length }} row(s)
        selected.
      </div>
      <button
        type="button"
        z-button
        zType="outline"
        zSize="sm"
        [zDisabled]="!table.getCanPreviousPage()"
        (click)="table.previousPage()"
      >
        Previous
      </button>
      <button
        type="button"
        z-button
        zType="outline"
        zSize="sm"
        [zDisabled]="!table.getCanNextPage()"
        (click)="table.nextPage()"
      >
        Next
      </button>
    </div>
  `,
  changeDetection: ChangeDetectionStrategy.OnPush,
  viewProviders: [provideIcons({ lucideChevronDown })],
  host: { class: 'block w-full' },
})
export class ZardDemoDataTableRowSelectionComponent {
  readonly data = signal<Payment[]>(PAYMENTS);

  readonly table = injectTable(() => ({
    features,
    columns,
    data: this.data(),
    getRowId: row => row.id,
    initialState: { pagination: { pageIndex: 0, pageSize: 5 } },
  }));

  protected readonly hideableColumns = computed(() => this.table.getAllColumns().filter(column => column.getCanHide()));

  protected readonly emailFilter = computed(() => (this.table.getColumn('email')?.getFilterValue() as string) ?? '');

  protected filterEmails(event: Event): void {
    this.table.getColumn('email')?.setFilterValue((event.target as HTMLInputElement).value);
  }
}

Reusable Components

The parts most data tables need come with the component. The [Faceted Filters](#faceted-filters) example below uses all three, with the features object shared the same way as in [Set up Table Features](#set-up-table-features).

  • z-data-table-column-header makes a header sortable and hideable, and pinnable when the table has columnPinningFeature. It reads its column from DI, so render it from the column definition.
  • z-data-table-pagination adds the selection count, a rows-per-page select, the page indicator and first, previous, next and last buttons.
  • z-data-table-view-options is a "View" dropdown that toggles the hideable columns.

Column Header

columnHelper.accessor('email', {
  header: () => flexRenderComponent(ZardDataTableColumnHeaderComponent, { inputs: { zTitle: 'Email' } }),
}),
Copy

Pagination Component

<z-data-table [zTable]="table" />
<z-data-table-pagination [zTable]="table" [zPageSizeOptions]="[10, 20, 50]" />
Copy

View Options

<div class="flex items-center py-4">
  <z-data-table-view-options [zTable]="table" />
</div>
Copy

Expandable Rows

With rowExpandingFeature, pass an ng-template to [zExpandedRow]: it renders in a full-width row under each expanded row, with the row as let-row. getRowCanExpand decides which rows can open.
OrderCustomerStatusTotal
ORD-1042Olivia MartinShipped$229.97
ORD-1043Jackson LeePaid$29.99
ORD-1044Isabella NguyenRefunded$462.50
ORD-1045William KimPaid$59.00
import { ChangeDetectionStrategy, Component, signal } from '@angular/core';

import { NgIcon, provideIcons } from '@ng-icons/core';
import { lucideChevronRight } from '@ng-icons/lucide';
import {
  createColumnHelper,
  flexRenderComponent,
  injectTable,
  injectTableCellContext,
  rowExpandingFeature,
  tableFeatures,
} from '@tanstack/angular-table';

import { ZardButtonComponent } from '@/shared/components/button';
import { type ZardDataTableColumnMeta, ZardDataTableImports } from '@/shared/components/data-table';

interface OrderItem {
  name: string;
  quantity: number;
  price: number;
}

interface Order {
  id: string;
  customer: string;
  date: string;
  status: 'paid' | 'shipped' | 'refunded';
  items: OrderItem[];
}

const ORDERS: Order[] = [
  {
    id: 'ORD-1042',
    customer: 'Olivia Martin',
    date: '2026-11-02',
    status: 'shipped',
    items: [
      { name: 'Mechanical Keyboard', quantity: 1, price: 129.99 },
      { name: 'USB-C Hub', quantity: 2, price: 49.99 },
    ],
  },
  {
    id: 'ORD-1043',
    customer: 'Jackson Lee',
    date: '2026-11-04',
    status: 'paid',
    items: [{ name: 'Wireless Mouse', quantity: 1, price: 29.99 }],
  },
  {
    id: 'ORD-1044',
    customer: 'Isabella Nguyen',
    date: '2026-11-07',
    status: 'refunded',
    items: [
      { name: '27" Monitor', quantity: 1, price: 349 },
      { name: 'Monitor Arm', quantity: 1, price: 89.5 },
      { name: 'HDMI Cable', quantity: 2, price: 12 },
    ],
  },
  {
    id: 'ORD-1045',
    customer: 'William Kim',
    date: '2026-11-09',
    status: 'paid',
    items: [{ name: 'Laptop Stand', quantity: 1, price: 59 }],
  },
];

const features = tableFeatures({
  rowExpandingFeature,
  columnMeta: {} as ZardDataTableColumnMeta,
});

const currency = new Intl.NumberFormat('en-US', { style: 'currency', currency: 'USD' });

const totalOf = (order: Order) => order.items.reduce((sum, item) => sum + item.quantity * item.price, 0);

/** The chevron that opens and closes the row's detail. */
@Component({
  selector: 'z-demo-order-expand-toggle',
  imports: [ZardButtonComponent, NgIcon],
  template: `
    <button
      type="button"
      z-button
      zType="ghost"
      zSize="icon"
      class="size-8"
      [attr.aria-expanded]="cell().row.getIsExpanded()"
      [attr.aria-label]="(cell().row.getIsExpanded() ? 'Collapse ' : 'Expand ') + cell().row.original.id"
      (click)="cell().row.toggleExpanded()"
    >
      <ng-icon
        name="lucideChevronRight"
        class="transition-transform rtl:rotate-180"
        [class.rotate-90]="cell().row.getIsExpanded()"
        aria-hidden="true"
      />
    </button>
  `,
  changeDetection: ChangeDetectionStrategy.OnPush,
  viewProviders: [provideIcons({ lucideChevronRight })],
})
export class OrderExpandToggleComponent {
  protected readonly cell = injectTableCellContext<typeof features, Order, unknown>();
}

const columnHelper = createColumnHelper<typeof features, Order>();

const columns = columnHelper.columns([
  columnHelper.display({
    id: 'expand',
    cell: () => flexRenderComponent(OrderExpandToggleComponent),
    meta: { cellClass: 'w-10' },
  }),
  columnHelper.accessor('id', { header: 'Order', meta: { cellClass: 'font-medium' } }),
  columnHelper.accessor('customer', { header: 'Customer' }),
  columnHelper.accessor('status', {
    header: 'Status',
    cell: ({ getValue }) => getValue().charAt(0).toUpperCase() + getValue().slice(1),
  }),
  columnHelper.accessor(totalOf, {
    id: 'total',
    header: 'Total',
    cell: ({ getValue }) => currency.format(getValue()),
    meta: { headerClass: 'text-end', cellClass: 'text-end font-medium' },
  }),
]);

@Component({
  selector: 'z-demo-data-table-expandable',
  imports: [ZardDataTableImports],
  template: `
    <z-data-table [zTable]="table" [zExpandedRow]="detail" />

    <ng-template #detail let-row>
      <div class="bg-muted/30 px-12 py-3 text-sm">
        <p class="text-muted-foreground mb-2">Ordered on {{ row.original.date }}</p>
        <ul class="flex flex-col gap-1">
          @for (item of row.original.items; track item.name) {
            <li class="flex justify-between gap-4">
              <span>{{ item.quantity }} × {{ item.name }}</span>
              <span class="tabular-nums">{{ format(item.quantity * item.price) }}</span>
            </li>
          }
        </ul>
      </div>
    </ng-template>
  `,
  changeDetection: ChangeDetectionStrategy.OnPush,
  host: { class: 'block w-full' },
})
export class ZardDemoDataTableExpandableComponent {
  readonly data = signal<Order[]>(ORDERS);

  readonly table = injectTable(() => ({
    features,
    columns,
    data: this.data(),
    getRowId: row => row.id,
    getRowCanExpand: () => true,
  }));

  protected format(value: number): string {
    return currency.format(value);
  }
}

Faceted Filters

A toolbar in the style of a task list. Each filter is a popover of checkable options; the counts next to them come from columnFacetingFeature with createFacetedUniqueValues(), so they follow the other filters.
TASK-8782
bugYou can not quantify the bus without parsing the neural SSL protocol
Backlog
Low
TASK-8745
featureTry to override the TCP firewall, maybe it will index the redundant panel
Done
High
TASK-8708
documentationUse the wireless RSS capacitor, then you can generate the solid state bandwidth
Todo
Medium
TASK-8671
bugThe SMTP card is down, synthesize the open-source sensor so we can reboot the feed
Canceled
Low
TASK-8634
featureNavigating the alarm will not do anything, we need to transmit the virtual array
In Progress
High
TASK-8597
documentationCalculating the program will not do anything, we need to override the online port
Backlog
Medium
TASK-8560
bugParse the primary XSS circuit so we can hack the bluetooth monitor
Done
Low
TASK-8523
featureCompressing the system will not do anything, we need to back up the cross-platform pixel
Todo
High
TASK-8486
documentationWe need to bypass the neural USB interface
Canceled
Medium
TASK-8449
bugI will connect the mobile matrix, that should copy the HDD panel
In Progress
Low
0 of 36 row(s) selected.
Page 1 of 4
import { ChangeDetectionStrategy, Component, computed, input, signal } from '@angular/core';

import { NgIcon, provideIcons } from '@ng-icons/core';
import {
  lucideArrowDown,
  lucideArrowRight,
  lucideArrowUp,
  lucideCheck,
  lucideCircle,
  lucideCircleCheck,
  lucideCircleHelp,
  lucideCircleOff,
  lucideCirclePlus,
  lucideTimer,
  lucideX,
} from '@ng-icons/lucide';
import {
  type Column,
  columnFacetingFeature,
  columnFilteringFeature,
  columnVisibilityFeature,
  createColumnHelper,
  createFacetedRowModel,
  createFacetedUniqueValues,
  createFilteredRowModel,
  createPaginatedRowModel,
  createSortedRowModel,
  filterFn_includesString,
  flexRenderComponent,
  injectTable,
  injectTableCellContext,
  rowPaginationFeature,
  rowSelectionFeature,
  rowSortingFeature,
  sortFn_alphanumeric,
  sortFn_text,
  tableFeatures,
} from '@tanstack/angular-table';

import { ZardBadgeComponent } from '@/shared/components/badge';
import { ZardButtonComponent } from '@/shared/components/button';
import { ZardCommandImports } from '@/shared/components/command';
import {
  type ZardDataTableColumnMeta,
  ZardDataTableColumnHeaderComponent,
  ZardDataTableImports,
} from '@/shared/components/data-table';
import { ZardInputComponent } from '@/shared/components/input';
import { ZardPopoverDirective } from '@/shared/components/popover';
import { ZardSeparatorComponent } from '@/shared/components/separator';

import { SelectAllRowsComponent, SelectRowComponent } from './row-selection';

interface Task {
  id: string;
  title: string;
  label: 'bug' | 'feature' | 'documentation';
  status: 'backlog' | 'todo' | 'in progress' | 'done' | 'canceled';
  priority: 'low' | 'medium' | 'high';
}

interface FilterOption {
  label: string;
  value: string;
  icon: string;
}

const STATUSES: FilterOption[] = [
  { value: 'backlog', label: 'Backlog', icon: 'lucideCircleHelp' },
  { value: 'todo', label: 'Todo', icon: 'lucideCircle' },
  { value: 'in progress', label: 'In Progress', icon: 'lucideTimer' },
  { value: 'done', label: 'Done', icon: 'lucideCircleCheck' },
  { value: 'canceled', label: 'Canceled', icon: 'lucideCircleOff' },
];

const PRIORITIES: FilterOption[] = [
  { value: 'low', label: 'Low', icon: 'lucideArrowDown' },
  { value: 'medium', label: 'Medium', icon: 'lucideArrowRight' },
  { value: 'high', label: 'High', icon: 'lucideArrowUp' },
];

const TITLES = [
  'You can not quantify the bus without parsing the neural SSL protocol',
  'Try to override the TCP firewall, maybe it will index the redundant panel',
  'Use the wireless RSS capacitor, then you can generate the solid state bandwidth',
  'The SMTP card is down, synthesize the open-source sensor so we can reboot the feed',
  'Navigating the alarm will not do anything, we need to transmit the virtual array',
  'Calculating the program will not do anything, we need to override the online port',
  'Parse the primary XSS circuit so we can hack the bluetooth monitor',
  'Compressing the system will not do anything, we need to back up the cross-platform pixel',
  'We need to bypass the neural USB interface',
  'I will connect the mobile matrix, that should copy the HDD panel',
  'Use the auxiliary TLS bus, then you can index the virtual microchip',
  'Generating the driver will not do anything, we need to quantify the wireless capacitor',
];

const LABELS: Task['label'][] = ['bug', 'feature', 'documentation'];

/** Deterministic sample tasks, so the demo looks the same on every render. */
const TASKS: Task[] = Array.from({ length: 36 }, (_, index) => ({
  id: `TASK-${8782 - index * 37}`,
  title: TITLES[index % TITLES.length],
  label: LABELS[(index * 7) % LABELS.length],
  status: STATUSES[(index * 3) % STATUSES.length].value as Task['status'],
  priority: PRIORITIES[(index * 5) % PRIORITIES.length].value as Task['priority'],
}));

const features = tableFeatures({
  columnFacetingFeature,
  columnFilteringFeature,
  columnVisibilityFeature,
  rowPaginationFeature,
  rowSelectionFeature,
  rowSortingFeature,
  facetedRowModel: createFacetedRowModel(),
  facetedUniqueValues: createFacetedUniqueValues(),
  filteredRowModel: createFilteredRowModel(),
  paginatedRowModel: createPaginatedRowModel(),
  sortedRowModel: createSortedRowModel(),
  filterFns: { includesString: filterFn_includesString },
  sortFns: { alphanumeric: sortFn_alphanumeric, text: sortFn_text },
  columnMeta: {} as ZardDataTableColumnMeta,
});

type TaskColumn = Column<typeof features, Task, unknown>;

const ICONS = {
  lucideArrowDown,
  lucideArrowRight,
  lucideArrowUp,
  lucideCheck,
  lucideCircle,
  lucideCircleCheck,
  lucideCircleHelp,
  lucideCircleOff,
  lucideCirclePlus,
  lucideTimer,
  lucideX,
};

/**
 * A popover of checkable options that filters one column. The counts come from the column's
 * faceted unique values, so they follow the other filters.
 */
@Component({
  selector: 'z-demo-data-table-faceted-filter',
  imports: [
    ZardButtonComponent,
    ZardBadgeComponent,
    ZardCommandImports,
    ZardPopoverDirective,
    ZardSeparatorComponent,
    NgIcon,
  ],
  template: `
    <button
      type="button"
      z-button
      zType="outline"
      zSize="sm"
      class="h-8 border-dashed"
      zPopover
      zAlign="start"
      [zContent]="content"
    >
      <ng-icon name="lucideCirclePlus" aria-hidden="true" />
      {{ title() }}
      @if (selected().size) {
        <z-separator zOrientation="vertical" class="mx-2 h-4" />
        <z-badge zType="secondary" class="rounded-sm px-1 font-normal lg:hidden">{{ selected().size }}</z-badge>
        <div class="hidden gap-1 lg:flex">
          @if (selected().size > 2) {
            <z-badge zType="secondary" class="rounded-sm px-1 font-normal">{{ selected().size }} selected</z-badge>
          } @else {
            @for (option of selectedOptions(); track option.value) {
              <z-badge zType="secondary" class="rounded-sm px-1 font-normal">{{ option.label }}</z-badge>
            }
          }
        </div>
      }
    </button>

    <ng-template #content>
      <z-command class="w-50" (zCommandSelected)="select($event.value)">
        <z-command-input [placeholder]="title()" />
        <z-command-list>
          <z-command-option-group zLabel="Options">
            @for (option of options(); track option.value) {
              <z-command-option [zLabel]="option.label" [zValue]="option.value">
                <span
                  data-slot="command-option-leading"
                  class="border-primary flex size-4 items-center justify-center rounded-sm border"
                  [class]="
                    selected().has(option.value) ? 'bg-primary text-primary-foreground' : 'opacity-50 [&_svg]:invisible'
                  "
                >
                  <ng-icon name="lucideCheck" class="size-3.5" aria-hidden="true" />
                </span>
                <ng-icon
                  data-slot="command-option-leading"
                  [name]="option.icon"
                  class="text-muted-foreground"
                  aria-hidden="true"
                />
                @if (counts().get(option.value); as count) {
                  <span data-slot="command-option-trailing" class="ms-auto font-mono text-xs">{{ count }}</span>
                }
              </z-command-option>
            }
          </z-command-option-group>
          @if (selected().size) {
            <z-command-divider />
            <z-command-option zLabel="Clear filters" [zValue]="clearValue" class="justify-center text-center" />
          }
        </z-command-list>
      </z-command>
    </ng-template>
  `,
  changeDetection: ChangeDetectionStrategy.OnPush,
  viewProviders: [provideIcons(ICONS)],
})
export class DataTableFacetedFilterComponent {
  readonly column = input.required<TaskColumn | undefined>();
  readonly title = input.required<string>();
  readonly options = input.required<FilterOption[]>();

  protected readonly selected = computed(
    () => new Set((this.column()?.getFilterValue() as string[] | undefined) ?? []),
  );

  protected readonly selectedOptions = computed(() =>
    this.options().filter(option => this.selected().has(option.value)),
  );

  protected readonly counts = computed(() => this.column()?.getFacetedUniqueValues() ?? new Map<string, number>());

  /** A value no option uses, so the "Clear filters" row can't collide with one. */
  protected readonly clearValue = Symbol('clear');

  protected select(value: unknown): void {
    if (value === this.clearValue) {
      this.column()?.setFilterValue(undefined);
      return;
    }

    const next = new Set(this.selected());
    const option = value as string;
    if (next.has(option)) {
      next.delete(option);
    } else {
      next.add(option);
    }
    this.column()?.setFilterValue(next.size ? [...next] : undefined);
  }
}

/** Icon and label of a status or priority, looked up in its options. */
@Component({
  selector: 'z-demo-task-option-cell',
  imports: [NgIcon],
  template: `
    @if (option(); as option) {
      <div class="flex items-center gap-2 whitespace-nowrap">
        <ng-icon [name]="option.icon" class="text-muted-foreground size-4" aria-hidden="true" />
        <span>{{ option.label }}</span>
      </div>
    }
  `,
  changeDetection: ChangeDetectionStrategy.OnPush,
  viewProviders: [provideIcons(ICONS)],
})
export class TaskOptionCellComponent {
  readonly options = input.required<FilterOption[]>();

  private readonly cell = injectTableCellContext<typeof features, Task, unknown>();
  protected readonly option = computed(() => this.options().find(option => option.value === this.cell().getValue()));
}

/** The title, led by its label. */
@Component({
  selector: 'z-demo-task-title-cell',
  imports: [ZardBadgeComponent],
  template: `
    <div class="flex gap-2">
      <z-badge zType="outline" class="capitalize">{{ cell().row.original.label }}</z-badge>
      <span class="max-w-60 truncate font-medium xl:max-w-80">{{ cell().row.original.title }}</span>
    </div>
  `,
  changeDetection: ChangeDetectionStrategy.OnPush,
})
export class TaskTitleCellComponent {
  protected readonly cell = injectTableCellContext<typeof features, Task, unknown>();
}

/** Keeps the rows whose value is one of the checked options. */
const inOptions = (row: { getValue: (id: string) => unknown }, id: string, value: string[]) =>
  value.includes(row.getValue(id) as string);

const columnHelper = createColumnHelper<typeof features, Task>();

const header = (zTitle: string) => () =>
  flexRenderComponent(ZardDataTableColumnHeaderComponent, { inputs: { zTitle } });

const columns = columnHelper.columns([
  columnHelper.display({
    id: 'select',
    header: () => flexRenderComponent(SelectAllRowsComponent),
    cell: () => flexRenderComponent(SelectRowComponent),
    enableSorting: false,
    enableHiding: false,
  }),
  columnHelper.accessor('id', {
    header: header('Task'),
    meta: { cellClass: 'w-20 whitespace-nowrap' },
    enableHiding: false,
  }),
  columnHelper.accessor('title', {
    header: header('Title'),
    cell: () => flexRenderComponent(TaskTitleCellComponent),
  }),
  columnHelper.accessor('status', {
    header: header('Status'),
    cell: () => flexRenderComponent(TaskOptionCellComponent, { inputs: { options: STATUSES } }),
    filterFn: inOptions,
  }),
  columnHelper.accessor('priority', {
    header: header('Priority'),
    cell: () => flexRenderComponent(TaskOptionCellComponent, { inputs: { options: PRIORITIES } }),
    filterFn: inOptions,
  }),
]);

@Component({
  selector: 'z-demo-data-table-faceted-filters',
  imports: [ZardDataTableImports, ZardButtonComponent, ZardInputComponent, DataTableFacetedFilterComponent, NgIcon],
  template: `
    <div class="flex items-center justify-between gap-2 py-4">
      <div class="flex flex-1 flex-wrap items-center gap-2">
        <input
          z-input
          class="h-8 w-38 lg:w-62"
          placeholder="Filter tasks..."
          aria-label="Filter tasks"
          [value]="titleFilter()"
          (input)="filterTitles($event)"
        />
        <z-demo-data-table-faceted-filter title="Status" [column]="table.getColumn('status')" [options]="statuses" />
        <z-demo-data-table-faceted-filter
          title="Priority"
          [column]="table.getColumn('priority')"
          [options]="priorities"
        />
        @if (isFiltered()) {
          <button type="button" z-button zType="ghost" zSize="sm" class="h-8" (click)="table.resetColumnFilters()">
            Reset
            <ng-icon name="lucideX" aria-hidden="true" />
          </button>
        }
      </div>
      <z-data-table-view-options [zTable]="table" />
    </div>
    <z-data-table [zTable]="table" />
    <z-data-table-pagination class="py-4" [zTable]="table" />
  `,
  changeDetection: ChangeDetectionStrategy.OnPush,
  viewProviders: [provideIcons({ lucideX })],
  host: { class: 'block w-full' },
})
export class ZardDemoDataTableFacetedFiltersComponent {
  protected readonly statuses = STATUSES;
  protected readonly priorities = PRIORITIES;

  readonly data = signal<Task[]>(TASKS);

  readonly table = injectTable(() => ({
    features,
    columns,
    data: this.data(),
    getRowId: row => row.id,
  }));

  protected readonly isFiltered = computed(() => this.table.atoms.columnFilters.get().length > 0);
  protected readonly titleFilter = computed(() => (this.table.getColumn('title')?.getFilterValue() as string) ?? '');

  protected filterTitles(event: Event): void {
    this.table.getColumn('title')?.setFilterValue((event.target as HTMLInputElement).value);
  }
}

Server-side Data

When the server pages, sorts and filters, set manualPagination, manualSorting and manualFiltering, keep that state in signals, and pass rowCount. An Angular resource() refetches when the state changes and cancels the request in flight; [zLoading] dims the rows meanwhile.
Payment
pay_0001successcustomer1@example.com$10.00
pay_0002pendingcustomer38@example.com$999.00
pay_0003failedcustomer75@example.com$998.00
pay_0004processingcustomer112@example.com$997.00
pay_0005successcustomer149@example.com$996.00
pay_0006pendingcustomer186@example.com$995.00
pay_0007failedcustomer23@example.com$994.00
pay_0008processingcustomer60@example.com$993.00
pay_0009successcustomer97@example.com$992.00
pay_0010pendingcustomer134@example.com$991.00
Page 1 of 20
import { ChangeDetectionStrategy, Component, computed, linkedSignal, resource, signal } from '@angular/core';

import {
  type ColumnFiltersState,
  columnFilteringFeature,
  createColumnHelper,
  flexRenderComponent,
  injectTable,
  type PaginationState,
  rowPaginationFeature,
  rowSortingFeature,
  type SortingState,
  tableFeatures,
  type Updater,
} from '@tanstack/angular-table';

import {
  type ZardDataTableColumnMeta,
  ZardDataTableColumnHeaderComponent,
  ZardDataTableImports,
} from '@/shared/components/data-table';
import { ZardInputComponent } from '@/shared/components/input';

import type { Payment } from './payments';

interface PaymentsQuery {
  pageIndex: number;
  pageSize: number;
  sorting: SortingState;
  email: string;
}

interface PaymentsPage {
  rows: Payment[];
  total: number;
}

const STATUSES: Payment['status'][] = ['success', 'processing', 'failed', 'pending'];

/** 200 payments standing in for a database table. */
const DATABASE: Payment[] = Array.from({ length: 200 }, (_, index) => ({
  id: `pay_${(index + 1).toString().padStart(4, '0')}`,
  amount: ((index * 7919) % 990) + 10,
  status: STATUSES[(index * 3) % STATUSES.length],
  email: `customer${((index * 37) % 200) + 1}@example.com`,
}));

/**
 * Stands in for `GET /api/payments?page=…&size=…&sort=…&email=…`: the server filters, sorts and
 * slices, and answers with one page and the total. Swap it for an `HttpClient` call.
 */
function fetchPayments(query: PaymentsQuery, abortSignal: AbortSignal): Promise<PaymentsPage> {
  return new Promise((resolve, reject) => {
    const timer = setTimeout(() => {
      let rows = DATABASE.filter(payment => payment.email.includes(query.email.toLowerCase()));

      const [sort] = query.sorting;
      if (sort) {
        const key = sort.id as keyof Payment;
        rows = [...rows].sort((a, b) => (a[key] > b[key] ? 1 : a[key] < b[key] ? -1 : 0) * (sort.desc ? -1 : 1));
      }

      const start = query.pageIndex * query.pageSize;
      resolve({ rows: rows.slice(start, start + query.pageSize), total: rows.length });
    }, 400);

    abortSignal.addEventListener('abort', () => {
      clearTimeout(timer);
      reject(abortSignal.reason);
    });
  });
}

/** Applies a TanStack updater (a value or a function of the previous value) to a signal. */
function apply<T>(updater: Updater<T>, previous: T): T {
  return typeof updater === 'function' ? (updater as (old: T) => T)(previous) : updater;
}

const features = tableFeatures({
  columnFilteringFeature,
  rowPaginationFeature,
  rowSortingFeature,
  columnMeta: {} as ZardDataTableColumnMeta,
});

const currency = new Intl.NumberFormat('en-US', { style: 'currency', currency: 'USD' });

const columnHelper = createColumnHelper<typeof features, Payment>();

const columns = columnHelper.columns([
  columnHelper.accessor('id', { header: 'Payment', enableSorting: false, meta: { cellClass: 'font-mono text-xs' } }),
  columnHelper.accessor('status', {
    header: () => flexRenderComponent(ZardDataTableColumnHeaderComponent, { inputs: { zTitle: 'Status' } }),
  }),
  columnHelper.accessor('email', {
    header: () => flexRenderComponent(ZardDataTableColumnHeaderComponent, { inputs: { zTitle: 'Email' } }),
  }),
  columnHelper.accessor('amount', {
    header: () => flexRenderComponent(ZardDataTableColumnHeaderComponent, { inputs: { zTitle: 'Amount' } }),
    cell: ({ getValue }) => currency.format(getValue()),
    meta: { cellClass: 'font-medium' },
  }),
]);

@Component({
  selector: 'z-demo-data-table-server-side',
  imports: [ZardDataTableImports, ZardInputComponent],
  template: `
    <div class="flex items-center py-4">
      <input
        z-input
        class="max-w-sm"
        placeholder="Filter emails..."
        aria-label="Filter emails"
        (input.debounce.300)="filterEmails($event)"
      />
    </div>
    <z-data-table [zTable]="table" [zLoading]="payments.isLoading()" />
    <z-data-table-pagination class="py-4" [zTable]="table" />
  `,
  changeDetection: ChangeDetectionStrategy.OnPush,
  host: { class: 'block w-full' },
})
export class ZardDemoDataTableServerSideComponent {
  readonly pagination = signal<PaginationState>({ pageIndex: 0, pageSize: 10 });
  readonly sorting = signal<SortingState>([]);
  readonly columnFilters = signal<ColumnFiltersState>([]);

  private readonly email = computed(
    () => (this.columnFilters().find(filter => filter.id === 'email')?.value as string | undefined) ?? '',
  );

  /** Refetches whenever the page, the sort or the filter changes, cancelling the request in flight. */
  readonly payments = resource({
    params: () => ({ ...this.pagination(), sorting: this.sorting(), email: this.email() }),
    loader: ({ params, abortSignal }) => fetchPayments(params, abortSignal),
  });

  /** The last page received, kept on screen while the next one loads. */
  private readonly page = linkedSignal<PaymentsPage | undefined, PaymentsPage>({
    source: () => this.payments.value(),
    computation: (value, previous) => value ?? previous?.value ?? { rows: [], total: 0 },
  });

  readonly table = injectTable(() => ({
    features,
    columns,
    data: this.page().rows,
    rowCount: this.page().total,
    getRowId: row => row.id,
    manualPagination: true,
    manualSorting: true,
    manualFiltering: true,
    state: {
      pagination: this.pagination(),
      sorting: this.sorting(),
      columnFilters: this.columnFilters(),
    },
    onPaginationChange: updater => this.pagination.update(previous => apply(updater, previous)),
    onSortingChange: updater => this.sorting.update(previous => apply(updater, previous)),
    onColumnFiltersChange: updater => {
      this.columnFilters.update(previous => apply(updater, previous));
      this.pagination.update(previous => ({ ...previous, pageIndex: 0 }));
    },
  }));

  protected filterEmails(event: Event): void {
    this.table.getColumn('email')?.setFilterValue((event.target as HTMLInputElement).value || undefined);
  }
}

Pinning and Resizing

With columnPinningFeature, pinned columns stay put while the rest scrolls; pin them in initialState or from the column header menu. With columnSizingFeature and columnResizingFeature, drag a header’s edge to resize it, or double-click it to reset. Pinning uses start and end, so it follows the reading direction.
Olivia Martinolivia@example.comStaff EngineerPlatformLisbon2021-03-15$168,000
Jackson Leejackson@example.comProduct DesignerDesignToronto2022-07-01$124,000
Isabella Nguyenisabella@example.comEngineering ManagerPaymentsBerlin2019-11-04$182,000
William Kimwill@example.comData AnalystGrowthSeoul2023-01-09$98,000
Sofia Davissofia@example.comFrontend EngineerPlatformSão Paulo2024-05-20$115,000
import { ChangeDetectionStrategy, Component, signal } from '@angular/core';

import {
  columnPinningFeature,
  columnResizingFeature,
  columnSizingFeature,
  createColumnHelper,
  flexRenderComponent,
  injectTable,
  tableFeatures,
} from '@tanstack/angular-table';

import {
  type ZardDataTableColumnMeta,
  ZardDataTableColumnHeaderComponent,
  ZardDataTableImports,
} from '@/shared/components/data-table';

interface Employee {
  name: string;
  email: string;
  role: string;
  department: string;
  location: string;
  startDate: string;
  salary: number;
}

const EMPLOYEES: Employee[] = [
  {
    name: 'Olivia Martin',
    email: 'olivia@example.com',
    role: 'Staff Engineer',
    department: 'Platform',
    location: 'Lisbon',
    startDate: '2021-03-15',
    salary: 168000,
  },
  {
    name: 'Jackson Lee',
    email: 'jackson@example.com',
    role: 'Product Designer',
    department: 'Design',
    location: 'Toronto',
    startDate: '2022-07-01',
    salary: 124000,
  },
  {
    name: 'Isabella Nguyen',
    email: 'isabella@example.com',
    role: 'Engineering Manager',
    department: 'Payments',
    location: 'Berlin',
    startDate: '2019-11-04',
    salary: 182000,
  },
  {
    name: 'William Kim',
    email: 'will@example.com',
    role: 'Data Analyst',
    department: 'Growth',
    location: 'Seoul',
    startDate: '2023-01-09',
    salary: 98000,
  },
  {
    name: 'Sofia Davis',
    email: 'sofia@example.com',
    role: 'Frontend Engineer',
    department: 'Platform',
    location: 'São Paulo',
    startDate: '2024-05-20',
    salary: 115000,
  },
];

const features = tableFeatures({
  columnPinningFeature,
  columnResizingFeature,
  columnSizingFeature,
  columnMeta: {} as ZardDataTableColumnMeta,
});

const currency = new Intl.NumberFormat('en-US', { style: 'currency', currency: 'USD', maximumFractionDigits: 0 });

const columnHelper = createColumnHelper<typeof features, Employee>();

const header = (zTitle: string) => () =>
  flexRenderComponent(ZardDataTableColumnHeaderComponent, { inputs: { zTitle } });

const columns = columnHelper.columns([
  columnHelper.accessor('name', { header: header('Name'), size: 180, meta: { cellClass: 'font-medium' } }),
  columnHelper.accessor('email', { header: header('Email'), size: 220 }),
  columnHelper.accessor('role', { header: header('Role'), size: 200 }),
  columnHelper.accessor('department', { header: header('Department'), size: 160 }),
  columnHelper.accessor('location', { header: header('Location'), size: 160 }),
  columnHelper.accessor('startDate', { header: header('Start date'), size: 150 }),
  columnHelper.accessor('salary', {
    header: header('Salary'),
    size: 140,
    cell: ({ getValue }) => currency.format(getValue()),
    meta: { cellClass: 'tabular-nums' },
  }),
]);

@Component({
  selector: 'z-demo-data-table-pinning-resizing',
  imports: [ZardDataTableImports],
  template: `
    <z-data-table [zTable]="table" />
  `,
  changeDetection: ChangeDetectionStrategy.OnPush,
  host: { class: 'block w-full' },
})
export class ZardDemoDataTablePinningResizingComponent {
  readonly data = signal<Employee[]>(EMPLOYEES);

  readonly table = injectTable(() => ({
    features,
    columns,
    data: this.data(),
    columnResizeMode: 'onChange',
    initialState: { columnPinning: { start: ['name'], end: ['salary'] } },
  }));
}

RTL

To enable RTL support in zard/ui, see the RTL configuration guide.
الحالةالمبلغ
ناجحken99@example.com‏٣١٦٫٠٠ US$
ناجحAbe45@example.com‏٢٤٢٫٠٠ US$
قيد المعالجةMonserrat44@example.com‏٨٣٧٫٠٠ US$
ناجحSilas22@example.com‏٨٧٤٫٠٠ US$
فشلcarmella@example.com‏٧٢١٫٠٠ US$
0 من 5 صف(وف) محدد.
// You will notice this example is rendered inside a wrapper that sets the dir and data-lang attributes, and
// reads its text from a translations helper. This is because this site is not RTL by default.
// In your application you won't need either: set dir="rtl" on <html> (or use the CDK Dir directive on a subtree)
// and write the text of your own language. See the RTL guide: https://zardui.com/docs/rtl

import { ChangeDetectionStrategy, Component, computed, signal } from '@angular/core';
import { FormsModule } from '@angular/forms';

import { NgIcon, provideIcons } from '@ng-icons/core';
import { lucideArrowUpDown, lucideChevronDown, lucideEllipsis } from '@ng-icons/lucide';
import {
  createColumnHelper,
  flexRenderComponent,
  injectTable,
  injectTableCellContext,
  injectTableContext,
  injectTableHeaderContext,
} from '@tanstack/angular-table';

import { ZardButtonComponent } from '@/shared/components/button';
import { ZardCheckboxComponent } from '@/shared/components/checkbox';
import { ZardDataTableImports } from '@/shared/components/data-table';
import { ZardDropdownImports } from '@/shared/components/dropdown';
import { ZardInputComponent } from '@/shared/components/input';
import { injectRtlTranslation, type ZardRtlTranslations } from '@/shared/demo-utils/rtl-translation';

import { type DataTableFeatures, features } from './features';
import { type Payment, PAYMENTS } from './payments';

const translations: ZardRtlTranslations<{
  filterEmails: string;
  columns: string;
  status: string;
  email: string;
  amount: string;
  actions: string;
  copyPaymentId: string;
  viewCustomer: string;
  viewPaymentDetails: string;
  selectAll: string;
  selectRow: string;
  openMenu: string;
  noResults: string;
  rowsSelected: string;
  rowsSelectedSuffix: string;
  previous: string;
  next: string;
  statuses: Record<Payment['status'], string>;
  locale: string;
}> = {
  en: {
    dir: 'ltr',
    values: {
      filterEmails: 'Filter emails...',
      columns: 'Columns',
      status: 'Status',
      email: 'Email',
      amount: 'Amount',
      actions: 'Actions',
      copyPaymentId: 'Copy payment ID',
      viewCustomer: 'View customer',
      viewPaymentDetails: 'View payment details',
      selectAll: 'Select all',
      selectRow: 'Select row',
      openMenu: 'Open menu',
      noResults: 'No results.',
      rowsSelected: 'of',
      rowsSelectedSuffix: 'row(s) selected.',
      previous: 'Previous',
      next: 'Next',
      statuses: { pending: 'Pending', processing: 'Processing', success: 'Success', failed: 'Failed' },
      locale: 'en-US',
    },
  },
  ar: {
    dir: 'rtl',
    values: {
      filterEmails: 'تصفية البريد الإلكتروني...',
      columns: 'الأعمدة',
      status: 'الحالة',
      email: 'البريد الإلكتروني',
      amount: 'المبلغ',
      actions: 'الإجراءات',
      copyPaymentId: 'نسخ معرف الدفع',
      viewCustomer: 'عرض العميل',
      viewPaymentDetails: 'عرض تفاصيل الدفع',
      selectAll: 'تحديد الكل',
      selectRow: 'تحديد الصف',
      openMenu: 'فتح القائمة',
      noResults: 'لا توجد نتائج.',
      rowsSelected: 'من',
      rowsSelectedSuffix: 'صف(وف) محدد.',
      previous: 'السابق',
      next: 'التالي',
      statuses: { pending: 'قيد الانتظار', processing: 'قيد المعالجة', success: 'ناجح', failed: 'فشل' },
      locale: 'ar-SA',
    },
  },
  he: {
    dir: 'rtl',
    values: {
      filterEmails: 'סנן אימיילים...',
      columns: 'עמודות',
      status: 'סטטוס',
      email: 'אימייל',
      amount: 'סכום',
      actions: 'פעולות',
      copyPaymentId: 'העתק מזהה תשלום',
      viewCustomer: 'צפה בלקוח',
      viewPaymentDetails: 'צפה בפרטי תשלום',
      selectAll: 'בחר הכל',
      selectRow: 'בחר שורה',
      openMenu: 'פתח תפריט',
      noResults: 'אין תוצאות.',
      rowsSelected: 'מתוך',
      rowsSelectedSuffix: 'שורות נבחרו.',
      previous: 'הקודם',
      next: 'הבא',
      statuses: { pending: 'ממתין', processing: 'מעבד', success: 'הצליח', failed: 'נכשל' },
      locale: 'he-IL',
    },
  },
};

/** Header checkbox, labelled in the selected language. */
@Component({
  selector: 'z-demo-rtl-select-all',
  imports: [ZardCheckboxComponent, FormsModule],
  template: `
    <z-checkbox
      [ngModel]="table().getIsAllPageRowsSelected()"
      (ngModelChange)="table().toggleAllPageRowsSelected($event)"
    >
      <span class="sr-only">{{ i18n.t().selectAll }}</span>
    </z-checkbox>
  `,
  changeDetection: ChangeDetectionStrategy.OnPush,
})
class RtlSelectAllComponent {
  protected readonly i18n = injectRtlTranslation(translations);
  protected readonly table = injectTableContext<DataTableFeatures, Payment>();
}

/** Row checkbox, labelled in the selected language. */
@Component({
  selector: 'z-demo-rtl-select-row',
  imports: [ZardCheckboxComponent, FormsModule],
  template: `
    <z-checkbox [ngModel]="cell().row.getIsSelected()" (ngModelChange)="cell().row.toggleSelected($event)">
      <span class="sr-only">{{ i18n.t().selectRow }}</span>
    </z-checkbox>
  `,
  changeDetection: ChangeDetectionStrategy.OnPush,
})
class RtlSelectRowComponent {
  protected readonly i18n = injectRtlTranslation(translations);
  protected readonly cell = injectTableCellContext<DataTableFeatures, Payment, unknown>();
}

/** Sortable email header. */
@Component({
  selector: 'z-demo-rtl-email-header',
  imports: [ZardButtonComponent, NgIcon],
  template: `
    <button type="button" z-button zType="ghost" class="-ms-2.5" (click)="toggle()">
      {{ i18n.t().email }}
      <ng-icon name="lucideArrowUpDown" aria-hidden="true" />
    </button>
  `,
  changeDetection: ChangeDetectionStrategy.OnPush,
  viewProviders: [provideIcons({ lucideArrowUpDown })],
})
class RtlEmailHeaderComponent {
  protected readonly i18n = injectRtlTranslation(translations);
  private readonly header = injectTableHeaderContext<DataTableFeatures, Payment, unknown>();

  protected toggle(): void {
    const { column } = this.header();
    column.toggleSorting(column.getIsSorted() === 'asc');
  }
}

/** Row actions menu. */
@Component({
  selector: 'z-demo-rtl-payment-actions',
  imports: [ZardButtonComponent, ZardDropdownImports, NgIcon],
  template: `
    <button type="button" z-button zType="ghost" zSize="icon" class="size-8" z-dropdown [zDropdownMenu]="menu">
      <span class="sr-only">{{ i18n.t().openMenu }}</span>
      <ng-icon name="lucideEllipsis" aria-hidden="true" />
    </button>
    <z-dropdown-menu-content #menu="zDropdownMenuContent" zAlign="end">
      <z-dropdown-menu-label>{{ i18n.t().actions }}</z-dropdown-menu-label>
      <z-dropdown-menu-item (click)="copyId()">{{ i18n.t().copyPaymentId }}</z-dropdown-menu-item>
      <z-dropdown-menu-separator />
      <z-dropdown-menu-item>{{ i18n.t().viewCustomer }}</z-dropdown-menu-item>
      <z-dropdown-menu-item>{{ i18n.t().viewPaymentDetails }}</z-dropdown-menu-item>
    </z-dropdown-menu-content>
  `,
  changeDetection: ChangeDetectionStrategy.OnPush,
  viewProviders: [provideIcons({ lucideEllipsis })],
  host: { class: 'flex justify-end' },
})
class RtlPaymentActionsComponent {
  protected readonly i18n = injectRtlTranslation(translations);
  private readonly cell = injectTableCellContext<DataTableFeatures, Payment, unknown>();

  protected copyId(): void {
    void navigator.clipboard?.writeText(this.cell().row.original.id);
  }
}

const columnHelper = createColumnHelper<typeof features, Payment>();

@Component({
  selector: 'z-demo-data-table-rtl',
  imports: [ZardDataTableImports, ZardButtonComponent, ZardDropdownImports, ZardInputComponent, NgIcon],
  template: `
    <div class="flex items-center gap-2 py-4">
      <input
        z-input
        class="max-w-sm"
        [placeholder]="i18n.t().filterEmails"
        [attr.aria-label]="i18n.t().filterEmails"
        [value]="emailFilter()"
        (input)="filterEmails($event)"
      />
      <button type="button" z-button zType="outline" class="ms-auto" z-dropdown [zDropdownMenu]="columnsMenu">
        {{ i18n.t().columns }}
        <ng-icon name="lucideChevronDown" aria-hidden="true" />
      </button>
      <z-dropdown-menu-content #columnsMenu="zDropdownMenuContent" zAlign="end">
        @for (column of hideableColumns(); track column.id) {
          <z-dropdown-menu-checkbox-item
            class="capitalize"
            [zChecked]="column.getIsVisible()"
            (zCheckedChange)="column.toggleVisibility($event)"
          >
            {{ column.id }}
          </z-dropdown-menu-checkbox-item>
        }
      </z-dropdown-menu-content>
    </div>
    <z-data-table [zTable]="table" [zEmptyText]="i18n.t().noResults" />
    <div class="flex items-center justify-end gap-2 py-4">
      <div class="text-muted-foreground flex-1 text-sm">
        {{ table.getFilteredSelectedRowModel().rows.length }} {{ i18n.t().rowsSelected }}
        {{ table.getFilteredRowModel().rows.length }} {{ i18n.t().rowsSelectedSuffix }}
      </div>
      <button
        type="button"
        z-button
        zType="outline"
        zSize="sm"
        [zDisabled]="!table.getCanPreviousPage()"
        (click)="table.previousPage()"
      >
        {{ i18n.t().previous }}
      </button>
      <button
        type="button"
        z-button
        zType="outline"
        zSize="sm"
        [zDisabled]="!table.getCanNextPage()"
        (click)="table.nextPage()"
      >
        {{ i18n.t().next }}
      </button>
    </div>
  `,
  changeDetection: ChangeDetectionStrategy.OnPush,
  viewProviders: [provideIcons({ lucideChevronDown })],
  host: { class: 'block w-full' },
})
export class ZardDemoDataTableRtlComponent {
  protected readonly i18n = injectRtlTranslation(translations);

  /** Built once; the header and cell functions read the language when they render, so they follow it. */
  private readonly columns = columnHelper.columns([
    columnHelper.display({
      id: 'select',
      header: () => flexRenderComponent(RtlSelectAllComponent),
      cell: () => flexRenderComponent(RtlSelectRowComponent),
      enableSorting: false,
      enableHiding: false,
    }),
    columnHelper.accessor('status', {
      header: () => this.i18n.t().status,
      cell: ({ getValue }) => this.i18n.t().statuses[getValue()],
    }),
    columnHelper.accessor('email', {
      header: () => flexRenderComponent(RtlEmailHeaderComponent),
      meta: { cellClass: 'lowercase' },
    }),
    columnHelper.accessor('amount', {
      header: () => this.i18n.t().amount,
      cell: ({ getValue }) =>
        new Intl.NumberFormat(this.i18n.t().locale, { style: 'currency', currency: 'USD' }).format(getValue()),
      meta: { cellClass: 'font-medium' },
    }),
    columnHelper.display({
      id: 'actions',
      cell: () => flexRenderComponent(RtlPaymentActionsComponent),
      enableHiding: false,
    }),
  ]);

  readonly data = signal<Payment[]>(PAYMENTS.slice(0, 5));

  readonly table = injectTable(() => ({
    features,
    columns: this.columns,
    data: this.data(),
    getRowId: row => row.id,
  }));

  protected readonly hideableColumns = computed(() => this.table.getAllColumns().filter(column => column.getCanHide()));

  protected readonly emailFilter = computed(() => (this.table.getColumn('email')?.getFilterValue() as string) ?? '');

  protected filterEmails(event: Event): void {
    this.table.getColumn('email')?.setFilterValue((event.target as HTMLInputElement).value);
  }
}

API Reference

z-data-table

Renders the header groups and the current row model of a TanStack table with z-table, through FlexRender. It follows the features the table declares: selected rows get data-state="selected", columnSizingFeature sets the column widths and adds resize handles with columnResizingFeature, and columnPinningFeature makes pinned columns sticky (pinning more than one column per side needs columnSizingFeature, which knows their widths). Column meta.headerClass and meta.cellClass (ZardDataTableColumnMeta) go on the column’s th and td.

Prop
[zTable]

The table instance returned by injectTable

Type
AngularTable<TFeatures, TData>
Default
—
[zExpandedRow]

Template rendered in a full-width row under each expanded row (rowExpandingFeature); the row is let-row

Type
TemplateRef<ZardDataTableExpandedRowContext>
Default
—
[zLoading]

Dims the rows and sets aria-busy while data loads

Type
boolean
Default
false
[zLoadingText]

Text shown instead of zEmptyText while loading with no rows

Type
string
Default
'Loading...'
[zEmptyText]

Text shown when there are no rows

Type
string
Default
'No results.'
[zTableClass]

Classes for the inner table[z-table]

Type
ClassValue
Default
''
[class]

Custom CSS classes

Type
ClassValue
Default
''

z-data-table-column-header

A header menu with Asc and Desc (rowSortingFeature), Pin to start, Pin to end and Unpin (columnPinningFeature), and Hide (columnVisibilityFeature) — each shows when the table has its feature. Render it from a column definition with flexRenderComponent; it reads the header from DI, so it takes no table input.

Prop
[zTitle]

The column title

Type
string
Default
—
[class]

Custom CSS classes

Type
ClassValue
Default
''

z-data-table-pagination

Selection count, rows-per-page select, page indicator and first/previous/next/last buttons. Needs the row pagination feature; the selection count shows when row selection is on.

Prop
[zTable]

The table instance returned by injectTable

Type
AngularTable<TFeatures, TData>
Default
—
[zPageSizeOptions]

Choices of the rows-per-page select

Type
number[]
Default
[10, 20, 25, 30, 40, 50]
[class]

Custom CSS classes

Type
ClassValue
Default
''

z-data-table-view-options

A "View" dropdown that toggles the hideable accessor columns. Needs the column visibility feature.

Prop
[zTable]

The table instance returned by injectTable

Type
AngularTable<TFeatures, TData>
Default
—
[zLabel]

Trigger label

Type
string
Default
'View'
[class]

Custom CSS classes

Type
ClassValue
Default
''
github iconwhatsapp icondiscord iconX icon

Made with ❤ in Brazil. Open source and available on GitHub .