Table

The RhTable component provides a way to display tabular data in a flexible and customizable way.

Usage

Once installed, you can import the RhTable component in your React application:

copy
import {RhTable} from "@rhythm-ui/react"

Then, you can use the RhTable component in your JSX code:

ShainaToyShaina Toy0723single21
SavanahMedhurstSavanah Medhurst20814single9
LillyJacobsonLilly Jacobson11295single45
KeyshawnHahnKeyshawn Hahn3753single54
DinoBauchDino Bauch1890complicated49

1 - 5 of 100 results

Showing 1 to 5 of 100 results
copy

<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
    }
  */
  

Table props

columnsany[][]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.
dataunknown[][]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.
globalFilterstringglobalFilter accepts a string which would be shown in the global filter search box.
expandedanyexpanded prop tracks the currently expanded rows in a hierarchical table
subRowsDataKeystringsubRowsDataKey serves as the identifier for the data field containing the hierarchical structure needed to enable the expand functionality
groupinganygrouping is used to keep track of the current grouping state.
isGroupingbooleanThe isGrouping allows you to specify a Grouping that can be used to group all columns of the table.
groupingIconanygroupingIcon 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
groupedIconanygroupedIcon 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
expansionIconanyexpansionIcon 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

Striped

The Striped option is a useful styling option to improve the appearance and readability of tables, especially when displaying large amounts of data.

ShainaToyShaina Toy0723single21
SavanahMedhurstSavanah Medhurst20814single9
LillyJacobsonLilly Jacobson11295single45
KeyshawnHahnKeyshawn Hahn3753single54
DinoBauchDino Bauch1890complicated49

1 - 5 of 100 results

Showing 1 to 5 of 100 results
copy

<RhTable
  columns={column}
  data={data}
  resultsPerPage={5}
  styleOptions={[
    'striped'
  ]}
/> 

Vertical Lines

The verticalLines option allows you to add them to create a more structured and organized look for the table.

ShainaToyShaina Toy0723single21
SavanahMedhurstSavanah Medhurst20814single9
LillyJacobsonLilly Jacobson11295single45
KeyshawnHahnKeyshawn Hahn3753single54
DinoBauchDino Bauch1890complicated49

1 - 5 of 100 results

Showing 1 to 5 of 100 results
copy

<RhTable
  columns={column}
  data={data}
  resultsPerPage={5}
  styleOptions={[
    'verticalLines'
  ]}
/> 

Condensed

The condensed option reduces this spacing to make the table more compact and space-efficient.

ShainaToyShaina Toy0723single21
SavanahMedhurstSavanah Medhurst20814single9
LillyJacobsonLilly Jacobson11295single45
KeyshawnHahnKeyshawn Hahn3753single54
DinoBauchDino Bauch1890complicated49

1 - 5 of 100 results

Showing 1 to 5 of 100 results
copy

<RhTable
  columns={column}
  data={data}
  resultsPerPage={5}
  styleOptions={[
    'simple',
    'condensed'
  ]}
/> 

Sticky Header

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.

ShainaToyShaina Toy0723single21
SavanahMedhurstSavanah Medhurst20814single9
LillyJacobsonLilly Jacobson11295single45
KeyshawnHahnKeyshawn Hahn3753single54
DinoBauchDino Bauch1890complicated49

1 - 5 of 100 results

Showing 1 to 5 of 100 results
copy

<RhTable
  columns={column}
  data={data}
  styleOptions={[
    'striped',
    'stickyHeader'
  ]}
/> 

Without Border

The withoutBorder option removes these borders to create a clean and minimalist look for the table.

ShainaToyShaina Toy0723single21
SavanahMedhurstSavanah Medhurst20814single9
LillyJacobsonLilly Jacobson11295single45
KeyshawnHahnKeyshawn Hahn3753single54
DinoBauchDino Bauch1890complicated49

1 - 5 of 100 results

Showing 1 to 5 of 100 results
copy

<RhTable
  columns={column}
  data={data}
  resultsPerPage={5}
  styleOptions={[
    'simple',
    'withoutBorder'
  ]}
/> 

Column Filter

The columnFilter prop is an object that contains filters for specific columns of the table.

ShainaToyShaina Toy0723single21
SavanahMedhurstSavanah Medhurst20814single9
LillyJacobsonLilly Jacobson11295single45
KeyshawnHahnKeyshawn Hahn3753single54
DinoBauchDino Bauch1890complicated49

1 - 5 of 100 results

Showing 1 to 5 of 100 results
copy

<RhTable
  columnFilter
  columns={column}
  data={data}
  styleOptions={[
    'simple',
    ]}
/> 

Loading

The isLoading prop is a boolean value that indicates whether the table data is currently being loaded.

copy

<RhTable
  columns={column}
  data={data}
  isLoading
  resultsPerPage={5}
  styleOptions={[
    'simple'
    ]}
/> 

No Data

The noDataContent prop allows you to specify custom content to be displayed in case the table data is empty.

No Data Found
copy

<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'
  ]}
/> 

Row Selection

The isRowSelection prop is a boolean value that indicates whether the table rows can be selected by the user.

ShainaToyShaina Toy0723single21
SavanahMedhurstSavanah Medhurst20814single9
LillyJacobsonLilly Jacobson11295single45
KeyshawnHahnKeyshawn Hahn3753single54
DinoBauchDino Bauch1890complicated49

1 - 5 of 100 results

Showing 1 to 5 of 100 results
copy

<RhTable
  columns={column}
  data={data}
  isRowSelection
  onRowSelection={function noRefCheck() {}}
  resultsPerPage={5}
  styleOptions={[
    'simple'
  ]}
/> 

Manual Pagination

The manualPagination prop allows you to manually control the pagination of the table, rather than having it automatically paginate based on the resultsPerPage prop.

copy

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>
    );

}; 

Global Search

The globalFilter allows you to specify a global filter that can be used to search across all columns of the table.

ShainaToyShaina Toy0723single21
SavanahMedhurstSavanah Medhurst20814single9
LillyJacobsonLilly Jacobson11295single45
KeyshawnHahnKeyshawn Hahn3753single54
DinoBauchDino Bauch1890complicated49

1 - 5 of 100 results

Showing 1 to 5 of 100 results
copy

<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>

Expanded

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.

GorakhnathNaik15Chakravartee_Trivedi@yahoo.co.in1997-02-26T10:36:06.225Z2014-01-02T18:01:59.037Z
HeemaShah16Sameer.Khatri@hotmail.com2000-10-18T02:31:34.758Z2006-03-11T15:09:40.669Z
BilvaKhanna8Lal15@yahoo.co.in1999-02-10T04:33:54.628Z2015-06-25T03:51:19.058Z

1 - 3 of 3 results

Showing 1 to 3 of 3 results
copy

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}
    />
  );
};

Grouping

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.

OfeliaWisozk26955relationship45%
ConnerLebsack27607single65%
JeraldTurcotte24225complicated66%
OvaSpencer39428complicated95%
TaliaDickinson12379complicated29%

1 - 5 of 20 results

Showing 1 to 5 of 20 results
copy

  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>
    );
  };

Grouping with Icon Modification

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.

OfeliaWisozk26955relationship45%
ConnerLebsack27607single65%
JeraldTurcotte24225complicated66%
OvaSpencer39428complicated95%
TaliaDickinson12379complicated29%

1 - 5 of 20 results

Showing 1 to 5 of 20 results
copy

  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>
    );
  };
  

Sub Component

The showSubComponent will enable to see the subComponent for every row on expansion.

Ofelia
Wisozk26955relationship45%
Conner
Lebsack27607single65%
Jerald
Turcotte24225complicated66%
Ova
Spencer39428complicated95%
Talia
Dickinson12379complicated29%

1 - 5 of 20 results

Showing 1 to 5 of 20 results
copy

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>
  );
}