Convert Figma logo to code with AI

react-component logotable

📋 Low-level table primitives for React, maintained in the Ant Design ecosystem.

1,373
616
1,373
187

Top Related Projects

An enterprise-class UI design language and React UI library

Material UI: Comprehensive React component library that implements Google's Material Design. Free forever.

28,402

🤖 Headless UI for building powerful tables & datagrids for TS/JS - React-Table, Vue-Table, Solid-Table, Svelte-Table

15,514

The best JavaScript Data Table for building Enterprise Applications. Supports React / Angular / Vue / Plain JavaScript.

JavaScript Data Grid / Data Table with a Spreadsheet Look & Feel. Works with React, Angular, and Vue. Supported by the Handsontable team ⚡

Feature-rich and customizable data grid React component

Quick Overview

React-component/table is a high-performance table component for React applications. It provides a flexible and feature-rich solution for displaying large datasets in a tabular format, with support for various customization options and advanced functionalities like virtualization and fixed columns.

Pros

  • Excellent performance with large datasets due to virtualization
  • Highly customizable with extensive API and theming options
  • Supports fixed columns and headers for better user experience
  • Active development and maintenance with regular updates

Cons

  • Steeper learning curve compared to simpler table components
  • Documentation can be overwhelming for beginners
  • Some advanced features may require additional configuration
  • Limited built-in styling options, requiring custom CSS for complex designs

Code Examples

  1. Basic table setup:
import Table from 'rc-table';

const columns = [
  { title: 'Name', dataIndex: 'name', key: 'name' },
  { title: 'Age', dataIndex: 'age', key: 'age' },
  { title: 'Address', dataIndex: 'address', key: 'address' },
];

const data = [
  { name: 'John Brown', age: 32, address: 'New York No. 1 Lake Park', key: 1 },
  { name: 'Jim Green', age: 42, address: 'London No. 1 Bridge Street', key: 2 },
];

const MyTable = () => <Table columns={columns} data={data} />;
  1. Table with fixed columns:
const columns = [
  { title: 'Name', dataIndex: 'name', key: 'name', width: 100, fixed: 'left' },
  { title: 'Age', dataIndex: 'age', key: 'age', width: 100 },
  { title: 'Address', dataIndex: 'address', key: 'address', width: 200 },
  { title: 'Operations', dataIndex: '', key: 'operations', fixed: 'right', width: 100 },
];

const MyFixedColumnsTable = () => <Table columns={columns} data={data} scroll={{ x: 1000 }} />;
  1. Table with expandable rows:
const expandedRowRender = (record) => <p>{record.description}</p>;

const MyExpandableTable = () => (
  <Table
    columns={columns}
    expandable={{
      expandedRowRender,
      defaultExpandedRowKeys: ['0'],
    }}
    dataSource={data}
  />
);

Getting Started

  1. Install the package:

    npm install rc-table
    
  2. Import and use the Table component in your React application:

    import Table from 'rc-table';
    import 'rc-table/assets/index.css';
    
    const MyComponent = () => {
      const columns = [
        { title: 'Name', dataIndex: 'name', key: 'name' },
        { title: 'Age', dataIndex: 'age', key: 'age' },
      ];
      const data = [
        { name: 'John Brown', age: 32, key: 1 },
        { name: 'Jim Green', age: 42, key: 2 },
      ];
    
      return <Table columns={columns} data={data} />;
    };
    
  3. Customize the table as needed using the available props and API options.

Competitor Comparisons

An enterprise-class UI design language and React UI library

Pros of ant-design

  • Comprehensive UI component library with a wide range of components beyond tables
  • Consistent design system and theming capabilities
  • Extensive documentation and community support

Cons of ant-design

  • Larger bundle size due to the full component library
  • Steeper learning curve for developers new to the ecosystem
  • Less flexibility for customizing individual components

Code Comparison

ant-design Table

import { Table } from 'antd';

const columns = [
  { title: 'Name', dataIndex: 'name', key: 'name' },
  { title: 'Age', dataIndex: 'age', key: 'age' },
];

<Table dataSource={data} columns={columns} />

react-component/table

import Table from 'rc-table';

const columns = [
  { title: 'Name', dataIndex: 'name', key: 'name' },
  { title: 'Age', dataIndex: 'age', key: 'age' },
];

<Table data={data} columns={columns} />

Summary

ant-design offers a comprehensive UI library with consistent design and extensive documentation, making it suitable for large-scale applications. However, it comes with a larger bundle size and less flexibility for customization. react-component/table, on the other hand, provides a more focused and lightweight solution for table components, offering greater customization options but with less out-of-the-box functionality and design consistency.

Material UI: Comprehensive React component library that implements Google's Material Design. Free forever.

Pros of Material-UI

  • Comprehensive UI component library with a wide range of pre-built components
  • Follows Google's Material Design guidelines for consistent and modern UI
  • Large community and extensive documentation for easier development

Cons of Material-UI

  • Larger bundle size due to the extensive component library
  • Steeper learning curve for customization and theming
  • May require more setup and configuration for specific use cases

Code Comparison

Material-UI Table:

import { Table, TableBody, TableCell, TableContainer, TableHead, TableRow, Paper } from '@mui/material';

<TableContainer component={Paper}>
  <Table>
    <TableHead>
      <TableRow>
        <TableCell>Header 1</TableCell>
        <TableCell>Header 2</TableCell>
      </TableRow>
    </TableHead>
    <TableBody>
      <TableRow>
        <TableCell>Data 1</TableCell>
        <TableCell>Data 2</TableCell>
      </TableRow>
    </TableBody>
  </Table>
</TableContainer>

react-component/table:

import Table from 'rc-table';

<Table
  columns={[
    { title: 'Header 1', dataIndex: 'col1', key: 'col1' },
    { title: 'Header 2', dataIndex: 'col2', key: 'col2' },
  ]}
  data={[
    { col1: 'Data 1', col2: 'Data 2' },
  ]}
/>
28,402

🤖 Headless UI for building powerful tables & datagrids for TS/JS - React-Table, Vue-Table, Solid-Table, Svelte-Table

Pros of Table

  • More flexible and feature-rich, supporting various UI frameworks beyond React
  • Better TypeScript support and type safety
  • Extensive documentation and examples for complex use cases

Cons of Table

  • Steeper learning curve due to its more complex API
  • Potentially larger bundle size for simpler table requirements

Code Comparison

Table (TanStack):

import { useTable } from '@tanstack/react-table'

function Table({ data, columns }) {
  const tableInstance = useTable({ columns, data })
  // ... render table using tableInstance
}

Table (react-component):

import Table from 'rc-table'

function MyTable({ data, columns }) {
  return <Table columns={columns} data={data} />
}

Key Differences

  • Table offers a more declarative approach with hooks
  • Table provides more granular control over table behavior
  • react-component/table has a simpler API for basic use cases

Use Cases

  • Table: Complex tables with advanced sorting, filtering, and pagination
  • react-component/table: Simpler tables with basic functionality

Community and Maintenance

  • Table has a larger and more active community
  • Both projects are well-maintained, but Table sees more frequent updates

Performance

  • Table may have better performance for large datasets due to virtualization support
  • react-component/table is generally lighter-weight for simpler tables
15,514

The best JavaScript Data Table for building Enterprise Applications. Supports React / Angular / Vue / Plain JavaScript.

Pros of ag-grid

  • More feature-rich with advanced functionality like filtering, sorting, and grouping
  • Better performance for large datasets
  • Extensive documentation and community support

Cons of ag-grid

  • Steeper learning curve due to its complexity
  • Larger bundle size, which may impact initial load times
  • Commercial license required for some advanced features

Code Comparison

ag-grid:

<AgGridReact
  columnDefs={columnDefs}
  rowData={rowData}
  defaultColDef={defaultColDef}
  onGridReady={onGridReady}
/>

react-component/table:

<Table
  columns={columns}
  dataSource={dataSource}
  pagination={pagination}
  onChange={handleTableChange}
/>

Key Differences

  • ag-grid offers more built-in features and customization options
  • react-component/table is simpler and easier to set up for basic use cases
  • ag-grid has a more complex API, while react-component/table follows a more straightforward approach
  • ag-grid is framework-agnostic, while react-component/table is specifically designed for React

Use Cases

  • Choose ag-grid for complex, data-intensive applications requiring advanced grid features
  • Opt for react-component/table for simpler React projects with basic table needs and a preference for lightweight solutions

JavaScript Data Grid / Data Table with a Spreadsheet Look & Feel. Works with React, Angular, and Vue. Supported by the Handsontable team ⚡

Pros of Handsontable

  • More feature-rich with advanced functionalities like data validation, filtering, and sorting
  • Supports various data types and formats, including spreadsheet-like capabilities
  • Extensive documentation and community support

Cons of Handsontable

  • Steeper learning curve due to its complexity and extensive API
  • Larger file size and potential performance impact for simpler use cases
  • Commercial license required for some features and use cases

Code Comparison

Handsontable:

const hot = new Handsontable(container, {
  data: data,
  rowHeaders: true,
  colHeaders: true,
  filters: true,
  dropdownMenu: true
});

Table:

<Table
  columns={columns}
  dataSource={data}
  pagination={pagination}
  onChange={handleChange}
/>

Key Differences

  • Handsontable offers a more Excel-like experience with advanced features
  • Table focuses on simplicity and ease of integration with React applications
  • Handsontable requires more configuration but provides greater flexibility
  • Table has a smaller footprint and is generally easier to set up for basic use cases

Use Cases

  • Choose Handsontable for complex data grids with spreadsheet-like functionality
  • Opt for Table when building simpler React-based tables with basic sorting and filtering needs

Feature-rich and customizable data grid React component

Error generating comparison

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

@rc-component/table

Ant Design Part of the Ant Design ecosystem.

📋 Low-level table primitives for React, maintained in the Ant Design ecosystem.

NPM version npm downloads build status Codecov bundle size dumi

English | 简体中文

Highlights

  • Flexible column, summary, fixed header, sticky, expandable row, and virtual table support.
  • TypeScript-first API designed for composition in design systems.
  • Used by Ant Design Table and other React data display experiences.

Install

npm install @rc-component/table

Usage

import Table from '@rc-component/table';
import type { ColumnsType } from '@rc-component/table';

interface User {
  key: string;
  name: string;
  age: number;
  address: string;
}

const columns: ColumnsType<User> = [
  { title: 'Name', dataIndex: 'name', key: 'name', width: 120 },
  { title: 'Age', dataIndex: 'age', key: 'age', width: 80 },
  { title: 'Address', dataIndex: 'address', key: 'address' },
];

const data: User[] = [
  { key: '1', name: 'Jack', age: 28, address: 'Somewhere' },
  { key: '2', name: 'Rose', age: 36, address: 'Somewhere else' },
];

export default () => <Table columns={columns} data={data} />;

Examples

Run the local dumi site:

npm install
npm start

Then open http://localhost:8000.

API

Properties

NameTypeDefaultDescription
tableLayoutauto | fixedauto | fixed for any columns is fixed or ellipsis or header is fixedhttps://developer.mozilla.org/en-US/docs/Web/CSS/table-layout
prefixClsStringrc-table
classNameStringadditional className
idStringidentifier of the container div
useFixedHeaderBooleanfalsewhether use separator table for header. better set width for columns
scrollObject{x: false, y: false}whether table can be scroll in x/y direction, x or y can be a number that indicated the width and height of table body
expandableObjectConfig expand props
expandable.defaultExpandAllRowsBooleanfalseExpand All Rows initially
expandable.defaultExpandedRowKeysString[][]initial expanded rows keys
expandable.expandedRowKeysString[]current expanded rows keys
expandable.expandedRowRenderFunction(recode, index, indent, expanded):ReactNodeContent render to expanded row
expandable.forceRenderBooleanfalseForce render expanded row content before expansion. In virtual mode, only rows currently mounted by the virtual list are force-rendered; off-screen rows may still be unmounted
expandable.expandedRowClassNamestring | (recode, index, indent) => stringget expanded row's className
expandable.columnTitleReactNode | Function({ expandIcon })Customize expand column title
expandable.expandRowByClickbooleanSupport expand by click row
expandable.expandIconColumnIndexNumber0The index of expandIcon which column will be inserted when expandIconAsCell is false
expandable.expandIconprops => ReactNodeDeprecated. Use components.ExpandIcon; retained as a row-only fallback
expandable.indentSizeNumber15indentSize for every level of data.i.children, better using with column.width specified
expandable.rowExpandable(record) => booleanConfig row support expandable
expandable.showExpandAllBooleanfalseShow expand all icon in the expand column header when using expandedRowRender
expandable.onExpandFunction(expanded, record)function to call when click expand icon
expandable.onExpandAllFunction(expanded)function to call when click expand all icon
expandable.onExpandedRowsChangeFunction(expandedRows)function to call when the expanded rows change
expandable.fixedString | Boolean-this expand icon will be fixed when table scroll horizontally: true or left or right and expandIconColumnIndex need to stay first or last
rowKeystring or Function(record, index):string'key'If rowKey is string, record[rowKey] will be used as key. If rowKey is function, the return value of rowKey(record, index) will be use as key.
rowClassNamestring or Function(record, index, indent):stringget row's className
rowRefFunction(record, index, indent):stringget row's ref key
dataObject[]data record array to be rendered
onRowFunction(record, index)Set custom props per each row.
onHeaderRowFunction(record, index)Set custom props per each header row.
showHeaderBooleantruewhether table head is shown
hiddenBooleanfalseHidden column.
titleFunction(currentData)table title render function
footerFunction(currentData)table footer render function
emptyTextReact.Node or FunctionNo DataDisplay text when data is empty
columnsObject[]The columns config of table, see table below
componentsObjectOverride table elements, see #171 for more details
components.ExpandIconReact.ComponentType<ExpandIconProps>Customize both row and expand-all icons. Receives type (row or all), prefixCls, expanded, expandable, onClick, and record for rows only
stickyboolean | {offsetHeader?: number, offsetScroll?: number, getContainer?: () => Window | HTMLElement }falsestick header and scroll bar
summary(data: readonly RecordType[]) => React.ReactNode-summary attribute in table component is used to define the summary row.
rowHoverablebooleantrueTable hover interaction

Methods

scrollTo

Table component exposes scrollTo method to scroll to a specific position:

const tblRef = useRef();
tblRef.current?.scrollTo({ key: 'rowKey', align: 'start' });
NameTypeDefaultDescription
indexnumber-Row index to scroll to
topnumber-Scroll to specific top position (in px)
keystring-Scroll to row by row key
offsetnumber-Additional offset from target position
alignstart | center | end | nearestnearestAlignment of the target element within the scroll container. start aligns to top, center to middle, end to bottom, nearest automatically chooses the closest alignment. Note: Virtual table does not support center.

Column Props

NameTypeDefaultDescription
keyStringkey of this column
classNameStringclassName of this column
colSpanNumberthead colSpan of this column
titleReact Nodetitle of this column
dataIndexStringdisplay field of the data record
widthString | Numberwidth of the specific proportion calculation according to the width of the columns
minWidthNumberthe minimum width of the column, only worked when tableLayout is auto
fixedString | Booleanthis column will be fixed when table scroll horizontally: true or 'left' or 'right'
alignStringspecify how cell content is aligned
ellipsisBooleanspecify whether cell content be ellipsized
rowScope'row' | 'rowgroup'Set scope attribute for all cells in this column
onCellFunction(record, index)Set custom props per each cell.
onHeaderCellFunction(record)Set custom props per each header cell.
renderFunction(value, row, index)The render function of cell, has three params: the text of this cell, the record of this row, the index of this row, it's return an object:{ children: value, props: { colSpan: 1, rowSpan:1 } } ==> 'children' is the text of this cell, props is some setting of this cell, eg: 'colspan' set td colspan, 'rowspan' set td rowspan

Summary Props

Table.Summary

NameTypeDefaultDescription
keyStringkey of this summary
fixedboolean | 'top' | 'bottom'-true fixes the summary row at the bottom of the table. top fixes the summary row at the top of the table, while bottom fixes it at the bottom. undefined or false makes the summary row scrollable along with the table.

Table.Summary.Row

NameTypeDefaultDescription
keyStringkey of this summary
classNameString-className of this summary row
styleReact.CSSProperties-style of this summary row
onClick(e?: React.MouseEvent<HTMLElement>) => void-The onClick attribute in Table.Summary.Row component can be used to set a click event handler for the summary row.

Development

npm install
npm start

The dumi site runs at http://localhost:8000 by default.

Run checks before sending a pull request:

npm run lint
npm run tsc
npm test
npm run build

Release

npm run prepublishOnly

The release flow is handled by @rc-component/np through the rc-np command after the package build.

Ecosystem

This package is part of the React Component organization and is maintained alongside Ant Design. The Ant Design mark above is used only as ecosystem context; the package itself stays framework-level and unstyled except for its bundled assets.

License

@rc-component/table is released under the MIT license.

NPM DownloadsLast 30 Days