Skip to content

Commit adec521

Browse files
committed
feat: table add expandColumnTitle slot
1 parent a6a270b commit adec521

File tree

4 files changed

+10
-3
lines changed

4 files changed

+10
-3
lines changed

components/table/Table.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@ const InteralTable = defineComponent<
205205
'headerCell',
206206
'customFilterIcon',
207207
'customFilterDropdown',
208+
'expandColumnTitle',
208209
],
209210
setup(props, { attrs, slots, expose, emit }) {
210211
devWarning(

components/table/context.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ export type ContextSlots = {
99
footer?: (...args: any[]) => any;
1010
summary?: (...args: any[]) => any;
1111
bodyCell?: (...args: any[]) => any;
12+
expandColumnTitle?: (...args: any[]) => any;
1213
headerCell?: (...args: any[]) => any;
1314
customFilterIcon?: (...args: any[]) => any;
1415
customFilterDropdown?: (...args: any[]) => any;

components/table/demo/expand.vue

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ When there's too much information to show and the table can't display all at onc
1717
</docs>
1818

1919
<template>
20-
<a-table :columns="columns" :data-source="data" :scroll="{ x: 2000 }">
20+
<a-table :columns="columns" :data-source="data" :scroll="{ x: 2000 }" :expand-column-width="100">
2121
<template #bodyCell="{ column }">
2222
<template v-if="column.key === 'action'">
2323
<a>Delete</a>
@@ -28,6 +28,9 @@ When there's too much information to show and the table can't display all at onc
2828
{{ record.description }}
2929
</p>
3030
</template>
31+
<template #expandColumnTitle>
32+
<span style="color: red">More</span>
33+
</template>
3134
</a-table>
3235
</template>
3336
<script lang="ts">

components/vc-table/hooks/useColumns.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { warning } from '../../vc-util/warning';
22
import type { ComputedRef, Ref } from 'vue';
3-
import { computed, watchEffect } from 'vue';
3+
import { renderSlot, computed, watchEffect } from 'vue';
44
import type {
55
ColumnsType,
66
ColumnType,
@@ -13,6 +13,7 @@ import type {
1313
} from '../interface';
1414
import { INTERNAL_COL_DEFINE } from '../utils/legacyUtil';
1515
import { EXPAND_COLUMN } from '../constant';
16+
import { useInjectSlots } from '../../table/context';
1617

1718
function flatColumns<RecordType>(columns: ColumnsType<RecordType>): ColumnType<RecordType>[] {
1819
return columns.reduce((list, column) => {
@@ -119,6 +120,7 @@ function useColumns<RecordType>(
119120
},
120121
transformColumns: Ref<(columns: ColumnsType<RecordType>) => ColumnsType<RecordType>>,
121122
): [ComputedRef<ColumnsType<RecordType>>, ComputedRef<readonly ColumnType<RecordType>[]>] {
123+
const contextSlots = useInjectSlots();
122124
// Add expand column
123125
const withExpandColumns = computed<ColumnsType<RecordType>>(() => {
124126
if (expandable.value) {
@@ -177,7 +179,7 @@ function useColumns<RecordType>(
177179
class: `${prefixCls.value}-expand-icon-col`,
178180
columnType: 'EXPAND_COLUMN',
179181
},
180-
title: '',
182+
title: renderSlot(contextSlots.value, 'expandColumnTitle', {}, () => ['']),
181183
fixed: fixedColumn,
182184
class: `${prefixCls.value}-row-expand-icon-cell`,
183185
width: expandColumnWidth.value,

0 commit comments

Comments
 (0)