Socket
Socket
Sign inDemoInstall

rc-table

Package Overview
Dependencies
13
Maintainers
9
Versions
426
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    rc-table

table ui component for react


Version published
Weekly downloads
1.2M
increased by7.32%
Maintainers
9
Install size
896 kB
Created
Weekly downloads
 

Package description

What is rc-table?

The rc-table npm package is a React component for rendering tables. It provides a range of features for creating and managing tables in a React application, including customizable columns, sorting, pagination, and more.

What are rc-table's main functionalities?

Customizable columns

Define the structure of the table by specifying columns with titles, data indexes, and keys.

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

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

Pagination

Easily paginate your table data by providing a pagination configuration object.

<Table columns={columns} dataSource={data} pagination={{ pageSize: 50 }} />

Sorting

Enable sorting on columns by providing a sorter function.

const columns = [
  { title: 'Name', dataIndex: 'name', key: 'name', sorter: (a, b) => a.name.length - b.name.length },
  { title: 'Age', dataIndex: 'age', key: 'age', sorter: (a, b) => a.age - b.age }
];

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

Selection

Allow row selection and handle selected rows with a callback function.

const rowSelection = {
  onChange: (selectedRowKeys, selectedRows) => {
    console.log(`selectedRowKeys: ${selectedRowKeys}`, 'selectedRows: ', selectedRows);
  }
};

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

Expandable Rows

Create expandable rows to show additional information about a row.

const expandedRowRender = record => <p>{record.description}</p>;

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

Other packages similar to rc-table

Readme

Source

rc-table

React table component with useful functions.

NPM version dumi build status Test coverage Dependencies DevDependencies npm download bundle size

install

rc-table

Development

npm install
npm start

Example

https://table.react-component.now.sh/

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):string'key'If rowKey is string, record[rowKey] will be used as key. If rowKey is function, the return value of rowKey(record) 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
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

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

License

rc-table is released under the MIT license.

Keywords

FAQs

Last updated on 12 May 2022

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc