Git Product home page Git Product logo

rsuite-table's Introduction

rsuite-table

A React table component.

npm GitHub Actions Coverage Status

Features

  • Support virtualized.
  • Support fixed header, fixed column.
  • Support custom adjustment column width.
  • Support for custom cell content.
  • Support for displaying a tree form.
  • Support for sorting.
  • Support for expandable child nodes
  • Support for RTL

Preview

  • Fixed Column

  • Custom Cell

  • Tree Table

  • Expandable

More Examples

Install

# use npm
npm i rsuite-table

# or use yarn
yarn add rsuite-table

# or use pnpm
pnpm add rsuite-table

Usage

import { Table, Column, HeaderCell, Cell } from 'rsuite-table';
import 'rsuite-table/lib/less/index.less'; // or 'rsuite-table/dist/css/rsuite-table.css'

const dataList = [
  { id: 1, name: 'a', email: '[email protected]', avartar: '...' },
  { id: 2, name: 'b', email: '[email protected]', avartar: '...' },
  { id: 3, name: 'c', email: '[email protected]', avartar: '...' }
];

const ImageCell = ({ rowData, dataKey, ...rest }) => (
  <Cell {...rest}>
    <img src={rowData[dataKey]} width="50" />
  </Cell>
);

const App = () => (
  <Table data={dataList}>
    <Column width={100} sortable fixed resizable>
      <HeaderCell>ID</HeaderCell>
      <Cell dataKey="id" />
    </Column>

    <Column width={100} sortable resizable>
      <HeaderCell>Name</HeaderCell>
      <Cell dataKey="name" />
    </Column>

    <Column width={100} sortable resizable>
      <HeaderCell>Email</HeaderCell>
      <Cell>
        {(rowData, rowIndex) => {
          return <a href={`mailto:${rowData.email}`}>{rowData.email}</a>;
        }}
      </Cell>
    </Column>

    <Column width={100} resizable>
      <HeaderCell>Avartar</HeaderCell>
      <ImageCell dataKey="avartar" />
    </Column>
  </Table>
);

API

<Table>

Property Type (Default) Description
affixHeader boolean,number Affix the table header to the specified position on the page
affixHorizontalScrollbar boolean,number Affix the table horizontal scrollbar to the specified position on the page
autoHeight boolean The height of the table will be automatically expanded according to the number of data rows, and no vertical scroll bar will appear
bordered boolean Show border
cellBordered boolean Show cell border
children (components: { Cell, HeaderCell, Column, ColumnGroup }) => React.ReactNode | React.ReactNode Render props that receives parameterized Cell, HeaderCell, Column, ColumnGroup components - making typescript usage more convenient
data * object[] Table data
defaultExpandAllRows boolean Expand all nodes By default
defaultExpandedRowKeys string[] Specify the default expanded row by rowkey
defaultSortType enum: 'desc', 'asc' Sort type
expandedRowKeys string[] Specify the default expanded row by rowkey (Controlled)
fillHeight boolean Force the height of the table to be equal to the height of its parent container. Cannot be used together with autoHeight.
headerHeight number(40) Table Header Height
height number(200) Table height
hover boolean (true) The row of the table has a mouseover effect
isTree boolean Show as Tree table
loading boolean Show loading
locale object: { emptyMessage: ('No data'), loading: ('Loading...') } Messages for empty data and loading states
minHeight number (0) Minimum height
onExpandChange (expanded:boolean,rowData:object)=>void Tree table, the callback function in the expanded node
onRowClick (rowData:object, event: SyntheticEvent)=>void Click the callback function after the row and return to rowDate
onRowContextMenu (rowData:object, event: SyntheticEvent)=>void Invoke the callback function on contextMenu and pass the rowData
onScroll (scrollX:object, scrollY:object)=>void Callback function for scroll bar scrolling
onSortColumn (dataKey:string, sortType:string)=>void Click the callback function of the sort sequence to return the value sortColumn, sortType
renderEmpty (info: React.ReactNode) => React.ReactNode Customized data is empty display content
renderLoading (loading: React.ReactNode) => React.ReactNode Customize the display content in the data load
renderRow (children?: ReactNode, rowData?: RowDataType) => ReactNode Custom row element
renderRowExpanded (rowDate?: Object) => React.ReactNode Customize what you can do to expand a zone
renderTreeToggle (icon:node,rowData:object,expanded:boolean)=> node Tree table, the callback function in the expanded node
rowClassName string , (rowData:object, rowIndex:number)=>string Add an optional extra class name to row
rowExpandedHeight number (100), (rowDate?: Object) => number Set the height of an expandable area
rowHeight number(46), (rowData: object) => number Row height
rowKey string ('key') Each row corresponds to the unique key in data
rtl boolean Right to left
shouldUpdateScroll boolean,(event)=>({x,y}) (true) Use the return value of shouldUpdateScroll to determine whether to update the scroll after the table size is updated.
showHeader boolean (true) Display header
sortColumn string Sort column name ˝
sortType enum: 'desc', 'asc' Sort type (Controlled)
virtualized boolean Effectively render large tabular data
width number Table width
wordWrap boolean,'break-all','break-word','keep-all' Whether to appear line breaks where text overflows its content box.

<Column>

Property Type (Default) Description
align enum: 'left','center','right' Alignment
colSpan number Merges column cells to merge when the dataKey value for the merged column is null or undefined.
fixed boolean, 'left', 'right' Fixed column
flexGrow number Set the column width automatically adjusts, when set flexGrow cannot set resizable and width property
fullText boolean Whether to display the full text of the cell content when the mouse is hovered
minWidth number(200) When you use flexGrow, you can set a minimum width by minwidth
onResize (columnWidth?: number, dataKey?: string) => void Callback after column width change
resizable boolean Customizable Resize Column width
rowSpan (rowData: any) => number Merges rows on the specified column.
sortable boolean Sortable
treeCol boolean A column of a tree.
verticalAlign enum: 'top', 'middle', 'bottom' Vertical alignment
width number Column width

sortable is used to define whether the column is sortable, but depending on what key sort needs to set a dataKey in Cell. The sort here is the service-side sort, so you need to handle the logic in the ' Onsortcolumn ' callback function of <Table>, and the callback function returns sortColumn, sortType values.

<ColumnGroup>

Property Type (Default) Description
align enum: 'left','center','right' Alignment
fixed boolean, 'left', 'right' Fixed column
groupHeaderHeight number The height of the header of the merged cell group. The default value is 50% of the table headerHeight
header React.ReactNode Group header
verticalAlign enum: 'top', 'middle', 'bottom' Vertical alignment

<HeaderCell>

Property Type (Default) Description
children React.ReactNode The table column header displays the content
renderSortIcon (sortType) => React.ReactNode Custom render sort icons on column headers

<Cell>

Property Type (Default) Description
dataKey string Data binding key, but also a sort of key
rowData object Row data
rowIndex number Row number

There are three ways to use <Cell>, as follows:

  • 1.Associate the fields in the data with dataKey.
<Column width="{100}" align="center">
  <HeaderCell>Name</HeaderCell>
  <Cell dataKey="name" />
</Column>
  • 2.Customize a <Cell>.
const NameCell = ({ rowData, ...props }) => (
  <Cell {...props}>
    <a href={`mailto:${rowData.email}`}>{rowData.name}<a>
  </Cell>
);

<Column width={100} align="center">
  <HeaderCell>Name</HeaderCell>
  <NameCell />
</Column>
  • 3.Customize functions directly within the <Cell>.
<Column width={100} align="center">
  <HeaderCell>Name</HeaderCell>
  <Cell>
    {(rowData, rowIndex) => {
      return <a href={`mailto:${rowData.email}`}>{rowData.name}</a>;
    }}
  </Cell>
</Column>

(For nested data read this: #158)

Table ref

Property Type Description
body HTMLDivElement The body element of the table
root HTMLDivElement The root element of the table
scrollLeft (left:number)=>void Set the number of pixels for horizontal scrolling of the table
scrollPosition {top:number,left:number} The scroll position of the table
scrollTop (top:number)=>void Set the number of pixels for vertical scrolling of the table

Type safety

We can pass generic type parameters to Table, Cell etc. for better type-safety when using typescript.

Passing a render prop to Table is recommended when using TS, as this will ensure that the right generic type parameter is automatically propagated to the Cell component.

const products: Product[] = [{ name: 'Pineapple' }];

<Table<Product, string> ref={table} data={products}>
  {({ Column, HeaderCell, Cell }) => (
    <>
      <Column>
        <HeaderCell>Name</HeaderCell>
        {/* No need for passing explicit type parameter to Cell */}
        <Cell>{row => row.name}</Cell>
      </Column>
    </>
  )}
</Table>;

In fact, the type parameter from table can be inferred from the data passed to it, so the type parameter to Table can also be skipped.

const products: Product[] = [{ name: 'Pineapple' }];

<Table data={products}>
  {({ Column, HeaderCell, Cell }) => (
    <>
      <Column>
        <HeaderCell>Name</HeaderCell>
        <Cell>{row => row.name}</Cell>
      </Column>
    </>
  )}
</Table>;

When writing reusable components, it is recommended to make your components generic as well. For example:

interface ImageCellProps<TKey extends string, TRow extends Record<TKey, string>> {
  rowData: TRow;
  dataKey: TKey;
  // ... any other props
}

const ImageCell = <TKey extends string, TRow extends Record<TKey, string>>({
  rowData,
  dataKey,
  ...rest
}: ImageCellProps<TKey, TRow>) => (
  <Cell<TRow, TKey> {...rest}>
    <img src={rowData[dataKey]} width="50" />
  </Cell>
);

rsuite-table's People

Contributors

b1rdex avatar dependabot[bot] avatar edymov avatar eiji03aero avatar fallenleavesguy avatar gami-404 avatar gomez avatar hiyangguo avatar jdeniau avatar justasdev avatar kirat-singh avatar lgtm-com[bot] avatar lorefnon avatar marvelsq avatar mynameisdu avatar neomusic avatar opinius avatar psebestyen avatar pyroboomka avatar sevenoutman avatar simonguo avatar superman66 avatar trondpet avatar vingeraycn avatar yanshibainu avatar yourvishal007 avatar z2015 avatar zhangguimei avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

rsuite-table's Issues

可以考虑完善一下排序功能

目前的排序的sortColumn只支持一个,可以考虑支持多个,举例一个场景就是:先按照出生日期排好序,然后按照英文名字典序在原来的基础上继续排序。

字体显示模糊问题

列表里面的字体,都是同样的字体和样式,但是一行模糊一行正常,这是什么问题?
image

Module not found: Error: Can't resolve '~rsuite-table/lib/less/index.less' in

ERROR in ./src/index.jsx
Module not found: Error: Can't resolve '~rsuite-table/lib/less/index.less' in '/Users/ccguo/Documents/ETH/Demo/src'
@ ./src/index.jsx 23:0-44
@ multi (webpack)-dev-server/client?http://localhost:8080 ./src/index.jsx
Child html-webpack-plugin for "index.html":
1 asset
[0] ./node_modules/html-webpack-plugin/lib/loader.js!./src/index.html 861 bytes {0} [built]
[1] ./node_modules/lodash/lodash.js 540 kB {0} [built]
[2] (webpack)/buildin/global.js 509 bytes {0} [built]
[3] (webpack)/buildin/module.js 517 bytes {0} [built]
ℹ 「wdm」: Failed to compile.

Variable @H500 is undefined

请问这是什么原因呀
./node_modules/rsuite-table/lib/less/index.less
Module build failed:

@pagination-background: #f5f5f5;
@resize-mouse-color: @H500;
^
Variable @H500 is undefined
in ***(项目路径名)/node_modules/rsuite-table/lib/less/variables.less (line 6, column 21)

滚动条拖动事件BUG

Table组件自己实现了一个滚动条样式,但是事件监听不正确,应该使用document.addEventListener来监听,这样即使鼠标移到了浏览器窗体外,仍然能继续响应事件,现在是我拖动“滚动条”的时候,鼠标到浏览器之外松开鼠标再回到页面上,滚动条仍属于拖动状态,会随鼠标滚动。另外默认滚动条样式非常丑,webkit内核可以通过CSS修改滚动条样式,有时候喜欢自己去改,希望能有个配置启用或禁用组件实现的滚动条样式。
重现页面:https://rsuitejs.com/rsuite-table/#%E5%88%86%E9%A1%B5

运行demo报错

这个文件当中依赖了rsuite,但貌似npm install安装的时候并没有安装rsuite
版本2.0.0

./node_modules/rsuite-table/lib/TablePagination.js
Module not found: Can't resolve 'rsuite' in '/Users/tangduck/projects/rui/my-app4/node_modules/rsuite-table/lib'

Table scroll bar problem

Can provide native scroll bar?
I want to do unlimited scrolling loading.There are some problems.When I scroll down and start loading the data.The data is loaded.But the scroll bar is still at the bottom

How can I get the scrollbar to return itself to the correct position, such as in the middle?

[violation] requestAnimationFrame

Hi, I'm using rsuite-table with my React application. I'm using the virtualized flag to display 10 to 60,000 rows of data. Here's the issue I'm facing, every time I scroll through the list of data on the table, it seems to be causing a requestAnimationFrame violation. Also, this might be what's causing my app's fps to hover only around 13 - 16fps on table scroll.

Screen Shot 2019-08-12 at 4 25 30 PM

Is there a solution on this? Am I missing something critical on how it should be used?

More info on my data table:

  • 11 Columns
  • 10 - 60,000 Rows
  • virtualized={true}
  • height={500}
  • 150width on all columns
  • bordered
  • cellBordered
  • headerHeight={80}

On:

  • Chrome Version 75.0.3770.142 (Official Build) (64-bit)
  • Mac

功能请求:横向滚动加入虚拟渲染

请问有没有后续增加table横向滚动增加虚拟渲染的计划,在使用中有列特别多的情况,目前table只做了竖向的虚拟渲染,这种情况下,渲染的dom量依然很大,上下滑动中有一些卡顿现象。不知道后续有没有这方面的计划。

分页组件样式引用的BUG

引用了index.less之后,分页组件并没有CSS被应用到,通过查看官网上的css发现,而是采用了类似bootstrap之类的分页组件样式,我引入一个bootstrap的外链,显示就正常了,虽然和表格主题并不搭配。

TypeError: Cannot read property 'prefix' of null

我在服务端引用
import {Table, Column, Cell} from 'rsuite-table';
webpack 打包编译 报 ‘Variable @H500 is undefined’ 这个错误。我在index.less 声明了 这个变量 @H500: blue 后 再打包编译 TypeError: Cannot read property 'prefix' of null。
详细错误如下:
D:\React 渲染\MyReact-table\node_modules\dom-lib\lib\transition\index.js:59
prefix = _getTransitionPropert.prefix,
^
TypeError: Cannot read property 'prefix' of null
at Object. (D:\React 渲染\MyReact-table\node_modules\dom-lib\lib\transition\index.js:59:36)
at Module._compile (module.js:641:30)
at Object.Module._extensions..js (module.js:652:10)
at Module.load (module.js:560:32)
at tryModuleLoad (module.js:503:12)
at Function.Module._load (module.js:495:3)
at Module.require (module.js:585:17)
at require (internal/module.js:11:18)
at Object. (D:\React 渲染\MyReact-table\node_modules\dom-lib\lib\index.js:60:20)
at Module._compile (module.js:641:30)

ios9.3及以下版本系统有bug

ios9.3及以下版本系统里面,toggleClass.js文件line22,当node为空数组的时候没有length属性,会直接调用line28的toggleClass方法,会导致dom-lib/lib/classNames/removeClass.js中13行的target.className报undefined

image

image

Cell 中内容过长时被截断的问题有解么?

Cell 中内容过长时因为用了text-overflow: ellipsis;导致内容被截断,请问有没有考虑过用换行的形式来展示么?换行的话会导致表格内容高度计算出错么?这个问题在无限滚动这种情况下是不是无解呢?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.