Table

A Table component is a structured UI element that organizes and displays data in rows and columns, making it easy to read and compare information. Tables can include features like sorting, filtering, pagination, and inline editing, allowing users to interact with the data efficiently. They are commonly used to present datasets, such as user information, product listings, or any structured content that benefits from a grid-like layout.

Demo

Rendered live, with the same build of the library you install.

NameEmailRole
Alicealice@example.comAdmin
Bobbob@example.comUser
Charliecharlie@example.comEditor

Usage

Table.tsx
import { NTable } from '@nayan-ui/react';
const columns = [
{ name: 'name', title: 'Name' },
{ name: 'email', title: 'Email' },
{ name: 'role', title: 'Role' }
];
const data = [
{ name: 'Alice', email: 'alice@example.com', role: 'Admin' },
{ name: 'Bob', email: 'bob@example.com', role: 'User' },
{ name: 'Charlie', email: 'charlie@example.com', role: 'Editor' }
];
const Table = () => {
return (
<div>
<NTable columns={columns} data={data} />
</div>
);
};
export default Table;

Attributes

17 props
NameTypeDefaultDetails
classNamestring' 'You can customise by passing tailwind classes.
captionClassNamestring' 'You can customise by passing tailwind classes.
headerClassNamestring' 'You can customise by passing tailwind classes.
headerRowClassNamestring' 'You can customise by passing tailwind classes.
headerCellClassNamestring' 'You can customise by passing tailwind classes.
bodyClassNamestring' 'You can customise by passing tailwind classes.
bodyRowClassNamestring' 'You can customise by passing tailwind classes.
bodyCellClassNamestring' 'You can customise by passing tailwind classes.
captionstringOptionalCaption for the table.
columnsNTableColumn<T>[]RequiredArray of table columns.
dataT[]RequiredArray of table data.
tablePropsReact.TableHTMLAttributes<HTMLTableElement>OptionalProps for table element.
rowProps(row: T, rowIndex: number) => React.HTMLAttributes<HTMLTableRowElement>OptionalFunction to get row props.
cellProps(row: T, col: NTableColumn<T>, rowIndex: number, colIndex: number) => React.TdHTMLAttributes<HTMLTableCellElement>OptionalFunction to get cell props.
variant'primary' | 'secondary''primary'Visual variant of the table.
emptyMessageReact.ReactNodeOptionalContent shown when table has no data.
getRowKey(row: T, index: number) => string | numberOptionalCustom key extractor for table rows.

Tags

Other components solving nearby problems.