Get Started
Components
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
| Name | Role | |
|---|---|---|
| Alice | alice@example.com | Admin |
| Bob | bob@example.com | User |
| Charlie | charlie@example.com | Editor |
Usage
import { NTable } from '@nayan-ui/react';const CustomComponent = ({row, col, ...remaining}: any) => {return <div className="text-accent">Oops</div>;};const Table = () => {const columnDef = [{ name: 'invoice', title: 'Invoice', className: 'w-[100px]' },{ name: 'status', title: 'Status' },{ name: 'method', title: 'Method' },{ name: 'amount', title: 'Amount', className: 'text-right' },{ name: 'custom', title: 'Custom', className: 'text-right', component: CustomComponent }];const data = [{ invoice: '10001', status: 'Completed', method: 'Credit Card', amount: '$1000' },{ invoice: '10002', status: 'In progress', method: 'Net Banking', amount: '$500' }];return <NTable className="bg-surface" caption="Invoice table" columnDef={columnDef} data={data} />;};export default Table;
Attributes
| Name | Type | Default | Details |
|---|---|---|---|
| className | string | ' ' | You can customise by passing tailwind classes. |
| captionClassName | string | ' ' | You can customise by passing tailwind classes. |
| headerClassName | string | ' ' | You can customise by passing tailwind classes. |
| headerRowClassName | string | ' ' | You can customise by passing tailwind classes. |
| headerCellClassName | string | ' ' | You can customise by passing tailwind classes. |
| bodyClassName | string | ' ' | You can customise by passing tailwind classes. |
| bodyRowClassName | string | ' ' | You can customise by passing tailwind classes. |
| bodyCellClassName | string | ' ' | You can customise by passing tailwind classes. |
| caption | string | Optional | Caption for the table. |
| columns | NTableColumn<T>[] | Required | Array of table columns. |
| data | T[] | Required | Array of table data. |
| tableProps | React.TableHTMLAttributes<HTMLTableElement> | Optional | Props for table element. |
| rowProps | (row: T, rowIndex: number) => React.HTMLAttributes<HTMLTableRowElement> | Optional | Function to get row props. |
| cellProps | (row: T, col: NTableColumn<T>, rowIndex: number, colIndex: number) => React.TdHTMLAttributes<HTMLTableCellElement> | Optional | Function to get cell props. |