Skip to content

Dynamic Table

Reusable typed table component used across modules for read-only display, row click handling, loading states, and optional row selection.

import React from "react";
import type { Column } from "@/components/BusinessTable";
interface DynamicTableProps<T> {
title?: string;
data: T[];
columns: Column<T>[];
rowKey: keyof T;
onSelect?: (id: string) => void;
actions?: React.ReactNode;
loading?: boolean;
enableRowSelection?: boolean;
onRowSelection?: (selectedIds: (string | number)[]) => void;
/** @deprecated Use `actions` instead. */
headerActions?: React.ReactNode;
}
PropTypeDescription
titlestringOptional header title
dataT[]Rows to render
columnsColumn<T>[]Column definitions
rowKeykeyof TField used to derive row id
onSelect(id: string) => voidRow click callback
actionsReactNodeHeader actions (preferred)
loadingbooleanShows loading row in table head
enableRowSelectionbooleanEnables checkbox selection
onRowSelection(selectedIds: (string | number)[]) => voidEmits selected row ids
headerActionsReactNodeDeprecated alias for actions
import { DynamicTable, type Column } from "@/components/DynamicTable";
type Team = {
id: number;
name: string;
status: "active" | "inactive";
};
const columns: Column<Team>[] = [
{ key: "name", label: "Name" },
{ key: "status", label: "Status" },
];
<DynamicTable<Team>
title="Teams"
data={teams}
columns={columns}
rowKey="id"
loading={isLoading}
onSelect={(id) => openTeam(id)}
actions={<button onClick={openCreate}>Create Team</button>}
/>;