The RhTable component provides a way to display tabular data in a flexible and customizable way.
Once installed, you can import the RhTable component in your React application:
import {RhTable} from "@rhythm-ui/react"
Then, you can use the RhTable component in your JSX code:
First Name | Last Name | Full Name | Age | Visits | Status | Profile Progress |
---|---|---|---|---|---|---|
Shaina | Toy | Shaina Toy | 0 | 723 | single | 21 |
Savanah | Medhurst | Savanah Medhurst | 20 | 814 | single | 9 |
Lilly | Jacobson | Lilly Jacobson | 11 | 295 | single | 45 |
Keyshawn | Hahn | Keyshawn Hahn | 3 | 753 | single | 54 |
Dino | Bauch | Dino Bauch | 18 | 90 | complicated | 49 |
1 - 5 of 100 results
<RhTable columns={column} data={data} /> // The structure of objects in the list of data /** { age: 0, firstName: 'Shaina', id: '11fada2a-c370-46df-ab7b-324c72d0a51d', lastName: 'Toy', progress: 21, status: 'single', subRows: undefined, visits: 723 }, { age: 20, firstName: 'Savanah', id: 'ff4fa600-6b66-4755-9dd0-671237d32341', lastName: 'Medhurst', progress: 9, status: 'single', subRows: undefined, visits: 814 } */
Name | Type | Default | Description |
---|---|---|---|
columns | any[] | [] | Column prop takes value as an array of objects having a key-value pair. Each object in the array contains the data of a column in key-value pairs. Keys for an object can be header,accessorKey, cell, footer, etc. To know more in detail about these key types and values, please refer to https://tanstack.com/table/v8/docs/guide/introduction. By default, this is an empty array. |
data | unknown[] | [] | data prop takes value as an array of objects having one or more than one key-value pair. By default, this is an empty array. |
globalFilter | string | globalFilter accepts a string which would be shown in the global filter search box. | |
expanded | any | expanded prop tracks the currently expanded rows in a hierarchical table | |
subRowsDataKey | string | subRowsDataKey serves as the identifier for the data field containing the hierarchical structure needed to enable the expand functionality | |
grouping | any | grouping is used to keep track of the current grouping state. | |
isGrouping | boolean | The isGrouping allows you to specify a Grouping that can be used to group all columns of the table. | |
groupingIcon | any | groupingIcon accepts an component which represents icon or text icon which will be placed next to the column header to represents that the column can be grouped | |
groupedIcon | any | groupedIcon accepts an component which represents icon or text icon which will be placed next to the column header to represents that the column has grouped | |
expansionIcon | any | expansionIcon accepts an component which represents icon or text icon which will be placed next to the cell that can be expandable to see more details |
The Striped option is a useful styling option to improve the appearance and readability of tables, especially when displaying large amounts of data.
First Name | Last Name | Full Name | Age | Visits | Status | Profile Progress |
---|---|---|---|---|---|---|
Shaina | Toy | Shaina Toy | 0 | 723 | single | 21 |
Savanah | Medhurst | Savanah Medhurst | 20 | 814 | single | 9 |
Lilly | Jacobson | Lilly Jacobson | 11 | 295 | single | 45 |
Keyshawn | Hahn | Keyshawn Hahn | 3 | 753 | single | 54 |
Dino | Bauch | Dino Bauch | 18 | 90 | complicated | 49 |
1 - 5 of 100 results
<RhTable columns={column} data={data} resultsPerPage={5} styleOptions={[ 'striped' ]} />
The verticalLines option allows you to add them to create a more structured and organized look for the table.
First Name | Last Name | Full Name | Age | Visits | Status | Profile Progress |
---|---|---|---|---|---|---|
Shaina | Toy | Shaina Toy | 0 | 723 | single | 21 |
Savanah | Medhurst | Savanah Medhurst | 20 | 814 | single | 9 |
Lilly | Jacobson | Lilly Jacobson | 11 | 295 | single | 45 |
Keyshawn | Hahn | Keyshawn Hahn | 3 | 753 | single | 54 |
Dino | Bauch | Dino Bauch | 18 | 90 | complicated | 49 |
1 - 5 of 100 results
<RhTable columns={column} data={data} resultsPerPage={5} styleOptions={[ 'verticalLines' ]} />
The condensed option reduces this spacing to make the table more compact and space-efficient.
First Name | Last Name | Full Name | Age | Visits | Status | Profile Progress |
---|---|---|---|---|---|---|
Shaina | Toy | Shaina Toy | 0 | 723 | single | 21 |
Savanah | Medhurst | Savanah Medhurst | 20 | 814 | single | 9 |
Lilly | Jacobson | Lilly Jacobson | 11 | 295 | single | 45 |
Keyshawn | Hahn | Keyshawn Hahn | 3 | 753 | single | 54 |
Dino | Bauch | Dino Bauch | 18 | 90 | complicated | 49 |
1 - 5 of 100 results
<RhTable columns={column} data={data} resultsPerPage={5} styleOptions={[ 'simple', 'condensed' ]} />
The stickyHeader option keeps the header in view at the top of the page, making it easier for the user to reference the column headers as they scroll through the table.
First Name | Last Name | Full Name | Age | Visits | Status | Profile Progress |
---|---|---|---|---|---|---|
Shaina | Toy | Shaina Toy | 0 | 723 | single | 21 |
Savanah | Medhurst | Savanah Medhurst | 20 | 814 | single | 9 |
Lilly | Jacobson | Lilly Jacobson | 11 | 295 | single | 45 |
Keyshawn | Hahn | Keyshawn Hahn | 3 | 753 | single | 54 |
Dino | Bauch | Dino Bauch | 18 | 90 | complicated | 49 |
1 - 5 of 100 results
<RhTable columns={column} data={data} styleOptions={[ 'striped', 'stickyHeader' ]} />
The withoutBorder option removes these borders to create a clean and minimalist look for the table.
First Name | Last Name | Full Name | Age | Visits | Status | Profile Progress |
---|---|---|---|---|---|---|
Shaina | Toy | Shaina Toy | 0 | 723 | single | 21 |
Savanah | Medhurst | Savanah Medhurst | 20 | 814 | single | 9 |
Lilly | Jacobson | Lilly Jacobson | 11 | 295 | single | 45 |
Keyshawn | Hahn | Keyshawn Hahn | 3 | 753 | single | 54 |
Dino | Bauch | Dino Bauch | 18 | 90 | complicated | 49 |
1 - 5 of 100 results
<RhTable columns={column} data={data} resultsPerPage={5} styleOptions={[ 'simple', 'withoutBorder' ]} />
The columnFilter prop is an object that contains filters for specific columns of the table.
First Name | Last Name | Full Name | Age | Visits | Status | Profile Progress |
---|---|---|---|---|---|---|
Shaina | Toy | Shaina Toy | 0 | 723 | single | 21 |
Savanah | Medhurst | Savanah Medhurst | 20 | 814 | single | 9 |
Lilly | Jacobson | Lilly Jacobson | 11 | 295 | single | 45 |
Keyshawn | Hahn | Keyshawn Hahn | 3 | 753 | single | 54 |
Dino | Bauch | Dino Bauch | 18 | 90 | complicated | 49 |
1 - 5 of 100 results
<RhTable columnFilter columns={column} data={data} styleOptions={[ 'simple', ]} />
The isLoading prop is a boolean value that indicates whether the table data is currently being loaded.
First Name | Last Name | Full Name | Age | Visits | Status | Profile Progress |
---|---|---|---|---|---|---|
<RhTable columns={column} data={data} isLoading resultsPerPage={5} styleOptions={[ 'simple' ]} />
The noDataContent prop allows you to specify custom content to be displayed in case the table data is empty.
First Name | Last Name | Full Name | Age | Visits | Status | Profile Progress |
---|---|---|---|---|---|---|
<RhTable columns={column} data={[]} noDataContent={<RhImage alt="No Data Found" className="inline w-[20%] grayscale" src="packages/kitchensink-nextjs/public/images/noData.png"/>} resultsPerPage={5} styleOptions={[ 'simple' ]} />
The isRowSelection prop is a boolean value that indicates whether the table rows can be selected by the user.
First Name | Last Name | Full Name | Age | Visits | Status | Profile Progress | |
---|---|---|---|---|---|---|---|
Shaina | Toy | Shaina Toy | 0 | 723 | single | 21 | |
Savanah | Medhurst | Savanah Medhurst | 20 | 814 | single | 9 | |
Lilly | Jacobson | Lilly Jacobson | 11 | 295 | single | 45 | |
Keyshawn | Hahn | Keyshawn Hahn | 3 | 753 | single | 54 | |
Dino | Bauch | Dino Bauch | 18 | 90 | complicated | 49 |
1 - 5 of 100 results
<RhTable columns={column} data={data} isRowSelection onRowSelection={function noRefCheck() {}} resultsPerPage={5} styleOptions={[ 'simple' ]} />
The manualPagination prop allows you to manually control the pagination of the table, rather than having it automatically paginate based on the resultsPerPage prop.
ID | Name | Trips | Airline | Slogan |
---|---|---|---|---|
const ManualPagination = (args) => { const PAGE_SIZE = 5; const [activePage, setActivePage] = useState(0); const [data, setData] = useState([]); const [isLoading, setIsLoading] = useState(true); const fetchData = async (endPoint, PAGE_SIZE, activePage) => { await axios .get(endPoint, { params: { size: PAGE_SIZE, page: activePage } }) .then((res) => { setData(res.data); setIsLoading(false); }) .catch(() => { alert('Error while fetching data!!'); }); }; useEffect(() => { setIsLoading(true); fetchData( 'https://api.instantwebtools.net/v1/passenger', PAGE_SIZE, activePage ); }, [activePage]); return ( <div> <RhTable data={data.data} isLoading={isLoading} columns={MunualPaginationColumns} styleOptions={['simple']} manualPagination={true} resultsPerPage={5} /> {data.data?.length > 0 && ( <RhPagination resultsPerPage={PAGE_SIZE} totalResults={data.totalPassengers - PAGE_SIZE} onChange={setActivePage} /> )} </div> ); };
The globalFilter allows you to specify a global filter that can be used to search across all columns of the table.
First Name | Last Name | Full Name | Age | Visits | Status | Profile Progress |
---|---|---|---|---|---|---|
Shaina | Toy | Shaina Toy | 0 | 723 | single | 21 |
Savanah | Medhurst | Savanah Medhurst | 20 | 814 | single | 9 |
Lilly | Jacobson | Lilly Jacobson | 11 | 295 | single | 45 |
Keyshawn | Hahn | Keyshawn Hahn | 3 | 753 | single | 54 |
Dino | Bauch | Dino Bauch | 18 | 90 | complicated | 49 |
1 - 5 of 100 results
<div className='flex flex-col gap-1 p-4'> <RhInput type='text' onChange={(e: { target: { value: SetStateAction<string>; }; }) => setGlobalFilter(e.target.value)} inputSize='sm' placeholder='Search' className='w-56' /> <RhTable columns={column} data={data} globalFilter="" resultsPerPage={5} setGlobalFilter={function noRefCheck() {}} styleOptions={[ 'simple' ]} /> </div>
The expand allows you to view hierarchical data in the table by expanding the row. the subRowsDataKey specify the key within the data that holds information about the sub-rows or child data associated with each main row. expanded and setExpanded will track the currently expanded rows in a hierarchical table.
Full Name | Details | ||||
---|---|---|---|---|---|
First Name | Last Name | Age | Email Address | Date Of Birth | Date Of Admission |
Gorakhnath | Naik | 15 | Chakravartee_Trivedi@yahoo.co.in | 1997-02-26T10:36:06.225Z | 2014-01-02T18:01:59.037Z |
Heema | Shah | 16 | Sameer.Khatri@hotmail.com | 2000-10-18T02:31:34.758Z | 2006-03-11T15:09:40.669Z |
Bilva | Khanna | 8 | Lal15@yahoo.co.in | 1999-02-10T04:33:54.628Z | 2015-06-25T03:51:19.058Z |
1 - 3 of 3 results
const ExpandableTable = () => { const [expanded, setExpanded] = useState({}); return ( <RhTable columns={columnsForExpandableView} data={dataForExpandableView} setExpanded={setExpanded} expanded={expanded} styleOptions={["simple", "verticalLines"]} resultsPerPage={10} subRowsDataKey={"subRows"} manualPagination={false} /> ); };
The isGrouping allows you to specify a Grouping that can be used to group all columns of the table. grouping and setGrouping handle the selected grouping states.
Name | Info | ||||
---|---|---|---|---|---|
More Info | |||||
First Name | Last Name | Age | Visits | Status | Profile Progress |
Ofelia | Wisozk | 26 | 955 | relationship | 45% |
Conner | Lebsack | 27 | 607 | single | 65% |
Jerald | Turcotte | 24 | 225 | complicated | 66% |
Ova | Spencer | 39 | 428 | complicated | 95% |
Talia | Dickinson | 12 | 379 | complicated | 29% |
1 - 5 of 20 results
const Grouping = () => { const [grouping, setGrouping] = useState([]); return ( <div className="flex flex-col gap-1 p-4"> <RhTable data={dataForGrouping} columns={columnsForGrouping} isGrouping={true} styleOptions={["simple", "verticalLines"]} manualPagination={false} resultsPerPage={5} grouping={grouping} setGrouping={setGrouping} /> </div> ); };
The groupedIcon and groupingIcon are the props which accepts an component which represents icon or text icon which will be placed next to the column header to represents that the column has grouped or can be grouped.
Name | Info | ||||
---|---|---|---|---|---|
More Info | |||||
First Name | Last Name | Age | Visits | Status | Profile Progress |
Ofelia | Wisozk | 26 | 955 | relationship | 45% |
Conner | Lebsack | 27 | 607 | single | 65% |
Jerald | Turcotte | 24 | 225 | complicated | 66% |
Ova | Spencer | 39 | 428 | complicated | 95% |
Talia | Dickinson | 12 | 379 | complicated | 29% |
1 - 5 of 20 results
const GroupingWithIconModification = () => { const [grouping, setGrouping] = useState([]); return ( <div className="flex flex-col gap-1 p-4"> <RhTable data={dataForGrouping} columns={columnsForGrouping} isGrouping={true} styleOptions={["simple", "verticalLines"]} manualPagination={false} resultsPerPage={5} grouping={grouping} setGrouping={setGrouping} groupedIcon={ <RhIcon icon="heroicons:check-circle-solid" className="text-2xl text-danger-500" /> } groupingIcon={ <RhIcon icon="heroicons:user-group-solid" className="text-2xl text-warning-500" /> } /> </div> ); };
The showSubComponent will enable to see the subComponent for every row on expansion.
Name | Info | ||||
---|---|---|---|---|---|
More Info | |||||
First Name | Last Name | Age | Visits | Status | Profile Progress |
Ofelia | Wisozk | 26 | 955 | relationship | 45% |
Conner | Lebsack | 27 | 607 | single | 65% |
Jerald | Turcotte | 24 | 225 | complicated | 66% |
Ova | Spencer | 39 | 428 | complicated | 95% |
Talia | Dickinson | 12 | 379 | complicated | 29% |
1 - 5 of 20 results
const SubComponent = () => { const renderSubComponent = ({ row }: any) => { const valuesOfRow = row.original; return ( <div className="mx-8 inline-block p-4 rounded bg-slate-500"> <div className="flex items-center"> <RhIcon icon="heroicons:user-solid" className="text-2xl text-white pr-1" /> <p className="m-0 text-white inline-block"> {valuesOfRow.firstName} {valuesOfRow.lastName} </p> </div> <p className="m-2 text-white">Check for more details</p> </div> ); }; return ( <div className="flex flex-col gap-1 p-4"> <RhTable data={dataForSubComponent} columns={columnsForSubComponent} showSubComponent={true} styleOptions={["simple"]} manualPagination={false} resultsPerPage={5} getRowCanExpand={() => true} renderSubComponent={renderSubComponent} /> </div> ); }