Convert Figma logo to code with AI

react-component logotable

React Table

1,287
589
1,287
179

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.

24,859

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

12,496

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

JavaScript data grid 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' },
  ]}
/>
24,859

🤖 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
12,496

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

Pros of react-data-grid

  • More feature-rich with built-in functionality like cell editing, sorting, and filtering
  • Better performance for large datasets due to virtualization
  • More active development and community support

Cons of react-data-grid

  • Steeper learning curve due to more complex API
  • Less flexibility for custom styling and layout

Code Comparison

react-data-grid:

import ReactDataGrid from 'react-data-grid';

const columns = [
  { key: 'id', name: 'ID' },
  { key: 'title', name: 'Title', editor: TextEditor }
];

<ReactDataGrid
  columns={columns}
  rows={rows}
  onRowsChange={setRows}
/>

table:

import Table from 'rc-table';

const columns = [
  { title: 'ID', dataIndex: 'id', key: 'id' },
  { title: 'Title', dataIndex: 'title', key: 'title' }
];

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

react-data-grid offers more built-in features like cell editing, while table provides a simpler API for basic table rendering. react-data-grid is better suited for complex, data-heavy applications, while table is more appropriate for simpler use cases where customization is a priority. The choice between the two depends on the specific requirements of your project, considering factors such as performance needs, desired features, and development complexity.

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

React table component with useful functions.

NPM version dumi build status Test coverage npm download bundle size

install

rc-table

Development

npm install
npm start

Example

https://table-react-component.vercel.app/

Usage

import Table from 'rc-table';

const columns = [
  {
    title: 'Name',
    dataIndex: 'name',
    key: 'name',
    width: 100,
  },
  {
    title: 'Age',
    dataIndex: 'age',
    key: 'age',
    width: 100,
  },
  {
    title: 'Address',
    dataIndex: 'address',
    key: 'address',
    width: 200,
  },
  {
    title: 'Operations',
    dataIndex: '',
    key: 'operations',
    render: () => <a href="#">Delete</a>,
  },
];

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

React.render(<Table columns={columns} data={data} />, mountNode);

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.expandedRowClassNameFunction(recode, index, indent):stringget expanded row's className
expandable.expandRowByClickbooleanSupport expand by click row
expandable.expandIconColumnIndexNumber0The index of expandIcon which column will be inserted when expandIconAsCell is false
expandable.expandIconprops => ReactNodeCustomize expand icon
expandable.indentSizeNumber15indentSize for every level of data.i.children, better using with column.width specified
expandable.rowExpandable(record) => booleanConfig row support expandable
expandable.onExpandFunction(expanded, record)function to call when click expand 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
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

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.

License

rc-table is released under the MIT license.

NPM DownloadsLast 30 Days