feat(Table): support virtual components.body (#47098)

* feat(Table): support virtual components.body

* docs: update table docs

* docs: add faq

* docs: update faq

* docs: update faq
This commit is contained in:
daisy 2024-01-26 16:37:27 +08:00 committed by GitHub
parent 4def7a2407
commit a62d7ec3db
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 15 additions and 7 deletions

View File

@ -1,7 +1,7 @@
## zh-CN
通过 `virtual` 开启虚拟滚动,此时 `scroll.x``scroll.y` 必须设置且为 `number` 类型。开启后不能使用 `components.body` 属性。
通过 `virtual` 开启虚拟滚动,此时 `scroll.x``scroll.y` 必须设置且为 `number` 类型。
## en-US
Set `virtual` to enable virtual scroll, and `scroll.x` and `scroll.y` must be set at the same time with `number` type. `components.body` cannot be used when `virtual` is enabled.
Set `virtual` to enable virtual scroll, and `scroll.x` and `scroll.y` must be set at the same time with `number` type.

View File

@ -118,7 +118,7 @@ Common props ref[Common props](/docs/react/common-props)
| --- | --- | --- | --- | --- |
| bordered | Whether to show all table borders | boolean | false | |
| columns | Columns of table | [ColumnsType](#column)\[] | - | |
| components | Override default table elements. Not support `components.body` when in `virtual` | [TableComponents](https://github.com/react-component/table/blob/75ee0064e54a4b3215694505870c9d6c817e9e4a/src/interface.ts#L129) | - | |
| components | Override default table elements | [TableComponents](https://github.com/react-component/table/blob/75ee0064e54a4b3215694505870c9d6c817e9e4a/src/interface.ts#L129) | - | |
| dataSource | Data record array to be displayed | object\[] | - | |
| expandable | Config expandable content | [expandable](#expandable) | - | |
| footer | Table footer renderer | function(currentPageData) | - | |
@ -141,7 +141,7 @@ Common props ref[Common props](/docs/react/common-props)
| onChange | Callback executed when pagination, filters or sorter is changed | function(pagination, filters, sorter, extra: { currentDataSource: \[], action: `paginate` \| `sort` \| `filter` }) | - | |
| onHeaderRow | Set props on per header row | function(columns, index) | - | |
| onRow | Set props on per row | function(record, index) | - | |
| virtual | Support virtual list. Not support `components.body` when enabled | boolean | - | 5.9.0 |
| virtual | Support virtual list | boolean | - | 5.9.0 |
### Table ref
@ -385,3 +385,7 @@ Fixed column use `z-index` to make it over other columns. You will find sometime
### How to custom render Table CheckboxFor example, adding Tooltip?
Since `4.1.0`, You can use [`rowSelection.renderCell`](https://ant.design/components/table/#rowselection) to custom render Table Checkbox. If you want to add Tooltip, please refer to this [demo](https://codesandbox.io/s/table-row-tooltip-v79j2v).
### Why does components.body.wrapper report an error when virtual is enabled?
Because virtual table needs to get its ref to do some calculations, so you need to use `React.forwardRef` wrapper and pass the ref to the dom

View File

@ -119,7 +119,7 @@ const columns = [
| --- | --- | --- | --- | --- |
| bordered | 是否展示外边框和列边框 | boolean | false | |
| columns | 表格列的配置描述,具体项见下表 | [ColumnsType](#column)\[] | - | |
| components | 覆盖默认的 table 元素`virtual` 下不支持 `components.body` | [TableComponents](https://github.com/react-component/table/blob/75ee0064e54a4b3215694505870c9d6c817e9e4a/src/interface.ts#L129) | - | |
| components | 覆盖默认的 table 元素 | [TableComponents](https://github.com/react-component/table/blob/75ee0064e54a4b3215694505870c9d6c817e9e4a/src/interface.ts#L129) | - | |
| dataSource | 数据数组 | object\[] | - | |
| expandable | 配置展开属性 | [expandable](#expandable) | - | |
| footer | 表格尾部 | function(currentPageData) | - | |
@ -142,7 +142,7 @@ const columns = [
| onChange | 分页、排序、筛选变化时触发 | function(pagination, filters, sorter, extra: { currentDataSource: \[], action: `paginate` \| `sort` \| `filter` }) | - | |
| onHeaderRow | 设置头部行属性 | function(columns, index) | - | |
| onRow | 设置行属性 | function(record, index) | - | |
| virtual | 支持虚拟列表,开启后不支持 `components.body` 自定义 | boolean | - | 5.9.0 |
| virtual | 支持虚拟列表 | boolean | - | 5.9.0 |
### Table ref
@ -385,3 +385,7 @@ return <Table rowKey={(record) => record.uid} />;
### 如何自定义渲染可选列的勾选框(比如增加 Tooltip
`4.1.0` 起,可以通过 [rowSelection](https://ant.design/components/table-cn/#rowselection) 的 `renderCell` 属性控制,可以参考此处 [Demo](https://codesandbox.io/s/table-row-tooltip-v79j2v) 实现展示 Tooltip 需求或其他自定义的需求。
### 为什么 components.body.wrapper 在 virtual 开启时会报错?
因为虚拟表格需要获取其 ref 做一些计算,所以你需要使用 `React.forwardRef` 包裹并传递 ref 到 dom。

View File

@ -153,7 +153,7 @@
"rc-slider": "~10.5.0",
"rc-steps": "~6.0.1",
"rc-switch": "~4.1.0",
"rc-table": "~7.37.0",
"rc-table": "~7.38.0",
"rc-tabs": "~14.0.0",
"rc-textarea": "~1.6.3",
"rc-tooltip": "~6.1.3",