import type { CSSProperties, ReactElement, ReactNode, Ref } from 'react'; import type { SxProp } from '../Layout/sx.js'; export type DataTableAlign = 'left' | 'center' | 'right'; export type RowId = string | number; export interface DataTableColumn> { /** Key into the row (and the sort field). Use `renderCell` for non-primitive values. */ field: string; /** Column header content. Defaults to `field`. */ headerName?: ReactNode; /** Fixed width in px. */ width?: number; /** Proportional width (flex-grow). Ignored when `width` is set. */ flex?: number; /** Cell text alignment. */ align?: DataTableAlign; /** Header text alignment. Defaults to `align`. */ headerAlign?: DataTableAlign; /** Allow sorting on this column. */ sortable?: boolean; /** Allow drag-to-resize on this column. Default `true`. */ resizable?: boolean; /** Custom cell renderer. */ renderCell?: (params: { row: R; value: unknown; field: string; }) => ReactNode; /** Derive the cell value from the row instead of `row[field]`. */ valueGetter?: (params: { row: R; field: string; }) => unknown; /** * Pin the column to an edge so it stays visible while the grid scrolls * horizontally. Pinned columns are moved ahead of / behind the rest. */ pinned?: 'left' | 'right'; } export type DataTableDensity = 'standard' | 'compact'; export type DataTableLayout = 'auto' | 'fixed'; export interface DataTableSort { field: string; sort: 'asc' | 'desc'; } export interface DataTablePaginationModel { /** Zero-based page index. */ page: number; pageSize: number; } export interface DataTableProps> { columns: DataTableColumn[]; rows: R[]; /** Stable id for a row. Defaults to `row.id`. */ getRowId?: (row: R) => RowId; /** Replace rows with skeleton placeholders. */ loading?: boolean; /** Total server-side row count — enables the pagination footer. */ rowCount?: number; paginationModel?: DataTablePaginationModel; onPaginationModelChange?: (model: DataTablePaginationModel) => void; /** * `'server'` (default): `rows` is already the current page and `rowCount` is the total. * `'client'`: `rows` is every row — the table slices the current page itself * and `rowCount` is not needed. Requires `paginationModel`. */ paginationMode?: 'server' | 'client'; /** Rows-per-page choices in the footer. Default `[10, 25, 50, 100]`. */ pageSizeOptions?: number[]; /** Show a "Go to page" input in the footer. */ showGoToPage?: boolean; /** Show a leading checkbox column. */ checkboxSelection?: boolean; rowSelectionModel?: RowId[]; onRowSelectionModelChange?: (ids: RowId[]) => void; /** Controlled sort. Header clicks emit `onSortModelChange` (server-driven). */ sortModel?: DataTableSort | null; onSortModelChange?: (sort: DataTableSort | null) => void; onRowClick?: (row: R) => void; /** Empty-state content. */ noRowsLabel?: ReactNode; /** Replaces the whole empty state (label and clear-filters action). */ emptyState?: ReactNode; /** * Turns the empty state into a "no results" state with a "Clear filters" * button that calls this. */ onClearFilters?: () => void; /** Per-field visibility (`false` hides). Omit for uncontrolled. Missing fields are visible. */ columnVisibility?: Record; onColumnVisibilityChange?: (visibility: Record) => void; /** Show a "Columns" toolbar button with a show/hide checklist. */ columnsMenu?: boolean; /** * With `checkboxSelection` and server pagination: once every row on the page * is selected, a banner offers "Select all {rowCount} rows" and calls this. * The table only knows the current page's ids, so selecting the rest is up to you. */ onSelectAllRows?: () => void; /** Marks the selection as covering every row — the banner then offers "Clear selection". */ allRowsSelected?: boolean; /** Turn off column resizing for every column. */ disableColumnResize?: boolean; /** Row height. `'compact'` halves the vertical cell padding. */ density?: DataTableDensity; /** * Width of the `checkboxSelection` column, in px. Defaults to 44. * * Worth a prop rather than a CSS override because the value is also what * flex columns are sized against under `tableLayout="fixed"` — narrowing the * column from a stylesheet leaves the rest of the table computing against * the old width. */ checkboxColumnWidth?: number; /** * Scroll the rows inside the grid, keeping the header row in place. * * `thead th` is already `position: sticky`, but that only engages when the * scrollport is the grid's own scroll element; by default the grid is as tall * as its rows and something further up the page scrolls, so the header * scrolls away with them. This makes `.cny-dt-scroll` the scrollport. * * The grid does not give itself a height — bound it from the outside (a * `height`/`maxHeight` in `sx`, or a flex parent), or there is nothing for * the rows to scroll within. */ stickyHeader?: boolean; /** * Column sizing model. `'auto'` (default) lets the browser size columns to * their content. `'fixed'` uses `table-layout: fixed` and a colgroup built * from each column's `width` / `flex`, which is what makes a `width` actually * bind and lets long cell content truncate instead of widening the table. * * Note `flex` has no effect under `'auto'`: it is emitted as a CSS `flex` on * ``/``, and flex does nothing on table cells. */ tableLayout?: DataTableLayout; /** Extra class for a row's `` — for per-row state the table cannot know. */ getRowClassName?: (row: R) => string | undefined; /** * Zebra-stripe the body rows. */ striped?: boolean; /** * Row virtualization: only the rows in (and just around) the scrollport are * in the DOM. `'auto'` (default) turns it on when there are more than 200 rows * and the grid is height-bounded (give it a `height` / `maxHeight`, or a flex * parent) - an unbounded grid has no scrollport, so every row is rendered. * `true` forces it on, `false` off. Virtualized rows have a fixed height * (`rowHeight`); long content is truncated with an ellipsis. */ virtualize?: boolean | 'auto'; /** Fixed row height in px when virtualized. Defaults to 45 (`standard`) / 37 (`compact`). */ rowHeight?: number; /** * Content for the bar above the header (search input, filters, buttons). * Shares the bar with the `columnsMenu` button, which sits at the right edge. */ toolbar?: ReactNode; className?: string; /** Inline style applied to the outer table container. */ style?: CSSProperties; /** * One-off CSS, same as `Box`'s `sx`: each value may be a scalar or a * responsive breakpoint map (`{ base, sm, md, lg, xl }`). Applied to the * outer table container. Scalar-only sx merges into inline style; responsive * sx injects a scoped class. */ sx?: SxProp; } export declare const DataTable: >(props: DataTableProps & { ref?: Ref; }) => ReactElement;