CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-tanstack--table-core

Headless UI for building powerful tables & datagrids for TS/JS

Pending
Overview
Eval results
Files

row-models.mddocs/

Row Models

Row processing pipelines that transform and filter table data through various operations. Row models are pluggable functions that process raw data into the final rows displayed in the table.

Capabilities

Core Row Model

The foundational row model that creates row instances from raw data.

/**
 * Creates the core row model from raw table data
 * @returns Row model factory function
 */
function getCoreRowModel<TData extends RowData>(): (
  table: Table<TData>
) => () => RowModel<TData>;

interface RowModel<TData extends RowData> {
  /** Array of row instances */
  rows: Row<TData>[];
  /** Flattened array including sub-rows */
  flatRows: Row<TData>[];
  /** Map of row IDs to row instances */
  rowsById: Record<string, Row<TData>>;
}

Usage Example:

import { createTable, getCoreRowModel } from "@tanstack/table-core";

const table = createTable({
  data: myData,
  columns: myColumns,
  getCoreRowModel: getCoreRowModel(),
});

// Access the row model
const rowModel = table.getRowModel();
console.log(rowModel.rows); // Array of row instances
console.log(rowModel.flatRows); // All rows including sub-rows
console.log(rowModel.rowsById); // Map for quick lookups

Sorted Row Model

Row model that applies sorting transformations to the data.

/**
 * Creates a sorted row model that applies sorting state
 * @returns Row model factory function that sorts rows
 */
function getSortedRowModel<TData extends RowData>(): (
  table: Table<TData>
) => () => RowModel<TData>;

Usage Example:

import { getSortedRowModel } from "@tanstack/table-core";

const table = createTable({
  data: myData,
  columns: myColumns,
  getCoreRowModel: getCoreRowModel(),
  getSortedRowModel: getSortedRowModel(),
  // Sorting configuration
  onSortingChange: setSorting,
  state: {
    sorting,
  },
});

// Rows are automatically sorted based on sorting state
const sortedRows = table.getRowModel().rows;

Filtered Row Model

Row model that applies column and global filtering to the data.

/**
 * Creates a filtered row model that applies filtering state
 * @returns Row model factory function that filters rows
 */
function getFilteredRowModel<TData extends RowData>(): (
  table: Table<TData>
) => () => RowModel<TData>;

Usage Example:

import { getFilteredRowModel } from "@tanstack/table-core";

const table = createTable({
  data: myData,
  columns: myColumns,
  getCoreRowModel: getCoreRowModel(),
  getFilteredRowModel: getFilteredRowModel(),
  // Filtering configuration
  onColumnFiltersChange: setColumnFilters,
  onGlobalFilterChange: setGlobalFilter,
  state: {
    columnFilters,
    globalFilter,
  },
});

// Rows are automatically filtered
const filteredRows = table.getRowModel().rows;

Grouped Row Model

Row model that applies grouping and aggregation to the data.

/**
 * Creates a grouped row model that applies grouping state
 * @returns Row model factory function that groups and aggregates rows
 */
function getGroupedRowModel<TData extends RowData>(): (
  table: Table<TData>
) => () => RowModel<TData>;

Usage Example:

import { getGroupedRowModel } from "@tanstack/table-core";

const table = createTable({
  data: myData,
  columns: myColumns,
  getCoreRowModel: getCoreRowModel(),
  getGroupedRowModel: getGroupedRowModel(),
  // Grouping configuration
  onGroupingChange: setGrouping,
  state: {
    grouping: ['department', 'role'],
  },
});

// Rows are grouped with aggregate values
const groupedRows = table.getRowModel().rows;

Expanded Row Model

Row model that handles row expansion state and sub-row visibility.

/**
 * Creates an expanded row model that handles row expansion
 * @returns Row model factory function that manages expanded state
 */
function getExpandedRowModel<TData extends RowData>(): (
  table: Table<TData>
) => () => RowModel<TData>;

/**
 * Utility function for expanding rows based on expanded state
 * @param rowModel - Input row model to expand
 * @param expanded - Expanded state mapping
 * @returns Expanded row model
 */
function expandRows<TData extends RowData>(
  rowModel: RowModel<TData>,
  expanded: ExpandedState
): RowModel<TData>;

Usage Example:

import { getExpandedRowModel } from "@tanstack/table-core";

const table = createTable({
  data: myData,
  columns: myColumns,
  getCoreRowModel: getCoreRowModel(),
  getExpandedRowModel: getExpandedRowModel(),
  // Sub-row configuration
  getSubRows: (row) => row.subRows,
  // Expansion state
  onExpandedChange: setExpanded,
  state: {
    expanded,
  },
});

// Only expanded rows and their sub-rows are visible
const expandedRows = table.getRowModel().rows;

Pagination Row Model

Row model that applies pagination to limit visible rows.

/**
 * Creates a paginated row model that applies pagination state
 * @returns Row model factory function that paginates rows
 */
function getPaginationRowModel<TData extends RowData>(): (
  table: Table<TData>
) => () => RowModel<TData>;

Usage Example:

import { getPaginationRowModel } from "@tanstack/table-core";

const table = createTable({
  data: myData,
  columns: myColumns,
  getCoreRowModel: getCoreRowModel(),
  getPaginationRowModel: getPaginationRowModel(),
  // Pagination configuration
  onPaginationChange: setPagination,
  state: {
    pagination: {
      pageIndex: 0,
      pageSize: 10,
    },
  },
});

// Only current page rows are visible
const paginatedRows = table.getRowModel().rows;
console.log(paginatedRows.length); // Max 10 rows

Faceted Row Models

Row models that provide faceted data for filtering interfaces.

/**
 * Creates a faceted row model for generating filter options
 * @returns Row model factory function for faceted data
 */
function getFacetedRowModel<TData extends RowData>(): (
  table: Table<TData>
) => () => RowModel<TData>;

/**
 * Creates faceted unique values for filter dropdowns
 * @returns Function that returns unique values for each column
 */
function getFacetedUniqueValues<TData extends RowData>(): (
  table: Table<TData>
) => () => Map<string, number>;

/**
 * Creates faceted min/max values for range filters
 * @returns Function that returns min/max values for each column
 */
function getFacetedMinMaxValues<TData extends RowData>(): (
  table: Table<TData>
) => () => [number, number] | undefined;

Usage Examples:

import { 
  getFacetedRowModel, 
  getFacetedUniqueValues, 
  getFacetedMinMaxValues 
} from "@tanstack/table-core";

const table = createTable({
  data: myData,
  columns: myColumns,
  getCoreRowModel: getCoreRowModel(),
  getFilteredRowModel: getFilteredRowModel(),
  getFacetedRowModel: getFacetedRowModel(),
  getFacetedUniqueValues: getFacetedUniqueValues(),
  getFacetedMinMaxValues: getFacetedMinMaxValues(),
});

// Get unique values for a column filter dropdown
const uniqueStatuses = table.getColumn('status')?.getFacetedUniqueValues();
// Map<string, number> - value to count mapping

// Get min/max for a range filter
const ageRange = table.getColumn('age')?.getFacetedMinMaxValues();
// [number, number] or undefined

Row Interface

The core row interface providing access to row data and methods.

interface Row<TData extends RowData> extends 
  CoreRow<TData>,
  VisibilityRow<TData>,
  ColumnPinningRow<TData>,
  RowPinningRow,
  ColumnFiltersRow<TData>,
  GroupingRow,
  RowSelectionRow,
  ExpandedRow {}

interface CoreRow<TData extends RowData> {
  /** Unique row identifier */
  id: string;
  /** Index of the row in the data array */
  index: number;
  /** Original data object for this row */
  original: TData;
  /** Nesting depth for sub-rows */
  depth: number;
  /** ID of parent row if this is a sub-row */
  parentId?: string;
  /** Array of sub-rows */
  subRows: Row<TData>[];
  /** Get value for a specific column */
  getValue<TValue = unknown>(columnId: string): TValue;
  /** Get unique values for a column across this row and sub-rows */
  getUniqueValues<TValue = unknown>(columnId: string): TValue[];
  /** Render value for a column using its cell renderer */
  renderValue<TValue = unknown>(columnId: string): TValue;
  /** Get all cells for this row */
  getAllCells(): Cell<TData, unknown>[];
  /** Get all leaf rows (including nested) */
  getLeafRows(): Row<TData>[];
  /** Get parent row if this is a sub-row */
  getParentRow(): Row<TData> | undefined;
  /** Get all parent rows up the hierarchy */
  getParentRows(): Row<TData>[];
}

Usage Examples:

// Access row data
const row = table.getRowModel().rows[0];
console.log(row.id); // Row ID
console.log(row.original); // Original data object
console.log(row.index); // Position in data array

// Get values from specific columns
const name = row.getValue('firstName');
const age = row.getValue<number>('age');

// Access cells
const cells = row.getAllCells();
const nameCell = cells.find(cell => cell.column.id === 'firstName');

// Work with hierarchical data
if (row.subRows.length > 0) {
  console.log('This row has sub-rows:', row.subRows);
}

const parent = row.getParentRow();
if (parent) {
  console.log('Parent row:', parent.original);
}

Row Creation

Internal row creation and processing utilities.

/**
 * Creates a row instance from raw data
 * @param table - Table instance
 * @param id - Row ID
 * @param original - Original data object
 * @param index - Row index
 * @param depth - Nesting depth
 * @param subRows - Array of sub-rows
 * @param parentId - Parent row ID
 * @returns Row instance
 */
function createRow<TData extends RowData>(
  table: Table<TData>,
  id: string,
  original: TData,
  index: number,
  depth: number,
  subRows?: Row<TData>[],
  parentId?: string
): Row<TData>;

Row models chain together to create sophisticated data processing pipelines. The typical order is: Core → Filtered → Sorted → Grouped → Expanded → Paginated.

Install with Tessl CLI

npx tessl i tessl/npm-tanstack--table-core

docs

builtin-functions.md

column-features.md

column-system.md

index.md

row-features.md

row-models.md

sorting-filtering.md

table-management.md

tile.json