# @rax-ui/table

> --- display: Table family: Data Display ---

Latest version **1.0.0-beta.12** (published 2019-10-17) · 0 weekly downloads

## Install

```sh
npm install @rax-ui/table
pnpm add @rax-ui/table
yarn add @rax-ui/table
bun add @rax-ui/table
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0-beta.12 |
| Published | 2019-10-17 |
| First published | 2019-09-04 |
| Weekly downloads | 0 |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 6 |
| Unpacked size | 58.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | yuzheng.tz |
| Maintainers | amdgigabyte, lianmin, myronliu347 |
| Keywords | Rax, rax-component |

## Links

- npm: https://www.npmjs.com/package/@rax-ui/table
- npm.io page: https://npm.io/package/@rax-ui/table

## Dependencies (6)

- [rax-icon](https://npm.io/package/rax-icon.md) ^1.0.0
- [rax-text](https://npm.io/package/rax-text.md) ^1.0.1
- [rax-view](https://npm.io/package/rax-view.md) ^1.0.1
- [@rax-ui/icon](https://npm.io/package/@rax-ui/icon.md) ^1.0.0-beta.10
- [@rax-ui/styles](https://npm.io/package/@rax-ui/styles.md) ^1.0.0-beta.10
- [rax-scrollview](https://npm.io/package/rax-scrollview.md) ^1.0.4

## Recent versions

- 1.0.0-beta.12 (latest) — 2019-10-17
- 1.0.0-beta.11 — 2019-10-17
- 1.0.0-beta.10 — 2019-10-09
- 1.0.0-beta.9 — 2019-10-08
- 1.0.0-beta.3 — 2019-09-04

## README

---
display: Table
family: Data Display
---

# Table

表格，展示行列数据

## API

### Props

| 参数 | 说明 | 类型 | 默认值 |
| --- | --- | --- | --- |
| bordered | 是否展示外边框和列边框 | boolean | false |
| columns | 表格列的配置描述，具体项见下表 | array | - |
| dataSource | 数据数组 | array | - |
| sortDirections | 支持的排序方式，取值为 'ascend' 'descend' null，设置在 table props 上对所有列生效 | Array | ['ascend', 'descend', null] |
| customStyles | 可自定义所有样式 | Function(defaultStyles):object | - |
| onHeaderRow | 设置头部行属性 | Function(column, index) | - |
| onRow | 设置行属性 | Function(record, index) | - |
| sortIconRender | 排序icon render | Function(column, sortOrder) {} | - |
| descIconRender | 字段说明icon render | Function(column) |  |
| onClickDescIcon | 自定义字段说明icon点击事件 | Function(column, event) |  |
| rowKey(暂未支持) | 表格行 key 的取值，可以是字符串或一个函数 | string / Function(record):string | 'key' |
| onChange | 排序变化时触发 | Function(sorter) |  |

### Column Props

列描述数据对象，是 columns 中的一项。

| 参数 | 说明 | 类型 | 默认值 |
| --- | --- | --- | --- |
| align | 设置列内容的对齐方式 | 'left' / 'right' / 'center' | 'left' |
| colSpan | 表头列合并,设置为 0 时，不渲染(暂未支持) | number | 1 |
| dataIndex | 列数据在数据项中对应的 key | string | - |
| fixed | 列是否固定(固定列需通过customStyles设置fixedTable.left（默认为20）为表格和屏幕左边的距离，详见demo用法) | boolean | false |
| key | React 需要的 key，如果已经设置了唯一的 `dataIndex`，可以忽略这个属性 | string | - |
| render | 生成复杂数据的渲染函数，参数分别为当前行的值，当前行数据，行索引，@return里面可以设置表格行/列合并 | Function(text, record, index) {} | - |
| defaultSortOrder | 默认排序顺序 | 'ascend' / 'descend' | - |
| sortOrder | 排序的受控属性，外界可用此控制列的排序，可设置为 `'ascend'` `'descend'` | string | - |
| sorter | 排序函数，本地排序使用一个函数(参考 [Array.sort](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort) 的 compareFunction)，需要服务端排序可设为 true | Function / boolean | - |
| sortDirections | 支持的排序方式，取值为 'ascend' 'descend' null | Array | ['ascend', 'descend', null] |
| title | 列头显示文字 | string | - |
| width | 列宽度 | number | - |
| onCell | 设置单元格属性 | Function(record, rowIndex) | - |
| onHeaderCell | 设置头部单元格属性 | Function(column) | - |
| children | 子列 | array，其中元素是column对象 | - |

### onRow 用法

适用于 `onRow` `onHeaderRow` `onCell` `onHeaderCell`。

```jsx
<Table
  onRow={(record) => {
    return {
      onClick: (event) => {},       // 点击行
      onLongPress: (event) => {},   // 长按行，H5不支持
      onAppear: (event) => {},
      onDisappear: (event) => {},
      customStyle: (defaultStyle) => {},         // 设置自定义样式

      // 仅适用于onCell、onHeaderCell
      titleCustomStyle: (defaultStyle) => {},    // 设置标题的自定义样式，
    };
  }}
  onHeaderRow={(column) => {
    return {
      onClick: () => {},        // 点击表头行
    };
  }}
/>
```

## 注意

按照 [React 的规范](https://facebook.github.io/react/docs/lists-and-keys.html#keys)，所有的组件数组必须绑定 key。在 Table 中，`dataSource` 和 `columns` 里的数据值都需要指定 `key` 值。对于 `dataSource` 默认将每列数据的 `key` 属性作为唯一的标识。

如果你的数据没有这个属性，务必使用 `rowKey` 来指定数据列的主键。若没有指定，控制台会出现以下的提示，表格组件也会出现各类奇怪的错误。

![控制台警告](https://os.alipayobjects.com/rmsportal/luLdLvhPOiRpyss.png)

```js
// 比如你的数据主键是 uid
return <Table rowKey="uid" />;
// 或
return <Table rowKey={record => record.uid} />;
```

---
_Source: https://npm.io/package/@rax-ui/table · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
