Skip to content

Commit 6fca13f

Browse files
authored
feat: add event update:expandedRowKeys for Table (#3892)
It's same as event expandedRowsChange, but can be used with prop as ':expandedRowKeys.sync="expandedRowKeys"' for short.
1 parent 61fa2cf commit 6fca13f

File tree

4 files changed

+14
-5
lines changed

4 files changed

+14
-5
lines changed

antdv-demo/docs/table/demo/expand-children.md

+9-1
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,26 @@
22
#### 树形数据展示
33
表格支持树形数据的展示,当数据中有 `children` 字段时会自动展示为树形表格,如果不需要或配置为其他字段可以用 `childrenColumnName` 进行配置。
44
可以通过设置 `indentSize` 以控制每一层的缩进宽度。
5+
事件 `expandedRowsChange``update:expandedRowKeys` 功能相同,用于接收展开行的 key 的列表。Vue 2.3.0 以上版本,属性 `expandedRowKeys` 可以和事件 `update:expandedRowKeys` 配合使用,简写为 `:expandedRowKeys.sync="expandedRowKeys"`
56
> 注:暂不支持父子数据递归关联选择。
67
</cn>
78
89
<us>
910
#### Tree data
1011
Display tree structure data in Table when there is field key `children` in dataSource, try to customize `childrenColumnName` property to avoid tree table structure.
1112
You can control the indent width by setting `indentSize`.
13+
Events `expandedRowsChange` and `update:expandedRowKeys` are the same, which are callbacks executed when the expanded rows change. With Vue 2.3.0 or above vesion, prop `expandedRowKeys` can be used with event `update:expandedRowKeys`, and can be written as `:expandedRowKeys.sync="expandedRowKeys"` for short.
1214
> Note, no support for recursive selection of tree structure data table yet.
1315
</us>
1416
1517
```vue
1618
<template>
17-
<a-table :columns="columns" :data-source="data" :row-selection="rowSelection" />
19+
<a-table
20+
:columns="columns"
21+
:data-source="data"
22+
:row-selection="rowSelection"
23+
:expanded-row-keys.sync="expandedRowKeys"
24+
/>
1825
</template>
1926
<script>
2027
const columns = [
@@ -120,6 +127,7 @@ export default {
120127
data,
121128
columns,
122129
rowSelection,
130+
expandedRowKeys: [],
123131
};
124132
},
125133
};

antdv-demo/docs/table/index.en-US.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
| dataSource | Data record array to be displayed | any\[] | - | |
1313
| defaultExpandAllRows | Expand all rows initially | boolean | `false` | |
1414
| defaultExpandedRowKeys | Initial expanded row keys | string\[] | - | |
15-
| expandedRowKeys | Current expanded row keys | string\[] | - | |
15+
| expandedRowKeys | Current expanded row keys. Can be used with `.sync`, see [`update:expandedRowKeys`](#Events). | string\[] | - | |
1616
| expandedRowRender | Expanded container render for each row | Function(record, index, indent, expanded):VNode\|slot-scope | - | |
1717
| expandIcon | Customize row expand Icon. | Function(props):VNode \| slot="expandIcon" slot-scope="props" | - | |
1818
| expandRowByClick | Whether to expand row by clicking anywhere in the whole row | boolean | `false` | |
@@ -40,7 +40,7 @@
4040
| --- | --- | --- |
4141
| change | Callback executed when pagination, filters or sorter is changed | Function(pagination, filters, sorter, { currentDataSource }) | |
4242
| expand | Callback executed when the row expand icon is clicked | Function(expanded, record) | |
43-
| expandedRowsChange | Callback executed when the expanded rows change | Function(expandedRows) | |
43+
| expandedRowsChange <br> update:expandedRowKeys | Callback executed when the expanded rows change | Function(expandedRowKeys) | |
4444

4545
#### customRow usage
4646

antdv-demo/docs/table/index.zh-CN.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
| dataSource | 数据数组 | any\[] | | |
1313
| defaultExpandAllRows | 初始时,是否展开所有行 | boolean | false | |
1414
| defaultExpandedRowKeys | 默认展开的行 | string\[] | - | |
15-
| expandedRowKeys | 展开的行,控制属性 | string\[] | - | |
15+
| expandedRowKeys | 展开的行,控制属性。可用 `.sync` 后缀, 参见 [`update:expandedRowKeys`](#事件) | string\[] | - | |
1616
| expandedRowRender | 额外的展开行 | Function(record, index, indent, expanded):VNode \| slot="expandedRowRender" slot-scope="record, index, indent, expanded" | - | |
1717
| expandIcon | 自定义展开图标 | Function(props):VNode \| slot="expandIcon" slot-scope="props" | - | |
1818
| expandRowByClick | 通过点击行来展开子行 | boolean | `false` | |
@@ -38,9 +38,9 @@
3838

3939
| 事件名称 | 说明 | 回调参数 |
4040
| --- | --- | --- |
41-
| expandedRowsChange | 展开的行变化时触发 | Function(expandedRows) |
4241
| change | 分页、排序、筛选变化时触发 | Function(pagination, filters, sorter, { currentDataSource }) |
4342
| expand | 点击展开图标时触发 | Function(expanded, record) |
43+
| expandedRowsChange <br> update:expandedRowKeys | 展开的行变化时触发 | Function(expandedRowKeys) |
4444

4545
#### customRow 用法
4646

components/vc-table/src/ExpandableTable.jsx

+1
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ const ExpandableTable = {
114114
if (!this.latestExpandedRows || !shallowEqual(this.latestExpandedRows, expandedRowKeys)) {
115115
this.latestExpandedRows = expandedRowKeys;
116116
this.__emit('expandedRowsChange', expandedRowKeys);
117+
this.__emit('update:expandedRowKeys', expandedRowKeys);
117118
}
118119

119120
if (!destroy) {

0 commit comments

Comments
 (0)