API Reference
Complete API documentation for the DataTable component
API Reference
Complete reference for all props, types, and configuration options.
DataTable Component
Props
Prop
Type
Example
<DataTable<User, any>
getColumns={getColumns}
fetchDataFn={useUsersData}
idField="id"
fetchByIdsFn={fetchUsersByIds}
pageSizeOptions={[10, 20, 50, 100]}
exportConfig={useExportConfig()}
onRowClick={handleRowClick}
renderToolbarContent={({ selectedRows }) => (
<ToolbarOptions selectedRows={selectedRows} />
)}
config={{
enableRowSelection: true,
enableSearch: true,
}}
/>DataTableConfig
Configuration object for table features.
Type Definition
interface DataTableConfig {
// Features
enableRowSelection?: boolean;
enableClickRowSelect?: boolean;
enableKeyboardNavigation?: boolean;
enableSearch?: boolean;
enableDateFilter?: boolean;
enableColumnVisibility?: boolean;
enableUrlState?: boolean;
// Sorting
defaultSortBy?: string;
defaultSortOrder?: 'asc' | 'desc';
// Search
searchPlaceholder?: string;
// Column Resizing
columnResizingTableId?: string;
// Export
allowExportNewColumns?: boolean;
// UI
size?: 'sm' | 'default' | 'lg';
}Properties
Prop
Type
SubRowsConfig
Configuration for hierarchical data (subrows).
Type Definition
interface SubRowsConfig {
enabled: boolean;
mode: 'same-columns' | 'custom-columns' | 'custom-component';
expandIconPosition?: 'first' | 'last' | 'custom';
getSubRowColumns?: () => ColumnDef<any>[];
CustomSubRowComponent?: React.ComponentType<{
subRows: any[];
parentRow: any;
}>;
}Properties
Prop
Type
Example
subRowsConfig={{
enabled: true,
mode: 'same-columns',
expandIconPosition: 'first',
}}ExportConfig
Configuration for data export.
Type Definition
interface ExportConfig {
headers: string[];
columnMapping: Record<string, string>;
columnWidths?: { wch: number }[];
transformFunction?: DataTransformFunction<T>;
entityName: string;
flatten?: boolean;
}Properties
Prop
Type
Example
{
headers: ["id", "name", "email", "created_at"],
columnMapping: {
id: "User ID",
name: "Full Name",
email: "Email Address",
created_at: "Registration Date",
},
columnWidths: [
{ wch: 10 },
{ wch: 25 },
{ wch: 30 },
{ wch: 20 },
],
transformFunction: (row) => ({
...row,
created_at: formatDate(row.created_at),
}),
entityName: "users",
}DataTransformFunction
Type for export transformation functions.
Type Definition
type DataTransformFunction<T> = (row: T) => Record<string, any>;Example
const transformData: DataTransformFunction<User> = (row: User) => ({
...row,
created_at: formatTimestampToReadable(row.created_at),
total_spent: formatCurrency(row.total_spent),
customer_tier: calculateTier(row.total_spent),
});ToolbarOptions
Passed to renderToolbarContent for custom toolbar.
Type Definition
interface ToolbarOptions<T> {
selectedRows: T[];
allSelectedIds: number[];
totalSelectedCount: number;
resetSelection: () => void;
}Properties
Prop
Type
Example
renderToolbarContent={({
selectedRows,
allSelectedIds,
totalSelectedCount,
resetSelection
}) => (
<div>
{totalSelectedCount > 0 && (
<Button onClick={resetSelection}>
Clear {totalSelectedCount} selected
</Button>
)}
</div>
)}ColumnDef
Column definition from TanStack Table with common patterns.
Essential Properties
Prop
Type
Example
{
accessorKey: "name",
header: ({ column }) => (
<DataTableColumnHeader column={column} title="Name" />
),
cell: ({ row }) => (
<div className="font-medium">{row.getValue("name")}</div>
),
size: 200,
enableSorting: true,
enableHiding: true,
}QueryHook
Type for data fetching hooks (React Query).
Type Definition
type QueryHook = (
page: number,
pageSize: number,
search: string,
dateRange: { from_date: string; to_date: string },
sortBy: string,
sortOrder: string
) => UseQueryResult<QueryResponse>;
interface QueryResponse {
data: T[];
pagination: {
page: number;
limit: number;
total_pages: number;
total_items: number;
};
}Example
export function useUsersData(
page: number,
pageSize: number,
search: string,
dateRange: { from_date: string; to_date: string },
sortBy: string,
sortOrder: string
) {
return useQuery({
queryKey: ["users", page, pageSize, search, dateRange, sortBy, sortOrder],
queryFn: () => fetchUsers({
page,
limit: pageSize,
search,
from_date: dateRange.from_date,
to_date: dateRange.to_date,
sort_by: sortBy,
sort_order: sortOrder,
}),
placeholderData: keepPreviousData,
});
}
// Required property
useUsersData.isQueryHook = true;Next Steps
- Configuration Guide - Detailed config options
- Features - Feature documentation
- Examples - Real-world implementations
How is this guide?