feat: use renderSlot
parent
3610140413
commit
a50684cb31
|
@ -3,17 +3,17 @@ import { computed } from 'vue';
|
||||||
import { inject, provide } from 'vue';
|
import { inject, provide } from 'vue';
|
||||||
|
|
||||||
export type ContextSlots = {
|
export type ContextSlots = {
|
||||||
emptyText?: (...args: any[]) => void;
|
emptyText?: (...args: any[]) => any;
|
||||||
expandIcon?: (...args: any[]) => void;
|
expandIcon?: (...args: any[]) => any;
|
||||||
title?: (...args: any[]) => void;
|
title?: (...args: any[]) => any;
|
||||||
footer?: (...args: any[]) => void;
|
footer?: (...args: any[]) => any;
|
||||||
summary?: (...args: any[]) => void;
|
summary?: (...args: any[]) => any;
|
||||||
bodyCell?: (...args: any[]) => void;
|
bodyCell?: (...args: any[]) => any;
|
||||||
headerCell?: (...args: any[]) => void;
|
headerCell?: (...args: any[]) => any;
|
||||||
customFilterIcon?: (...args: any[]) => void;
|
customFilterIcon?: (...args: any[]) => any;
|
||||||
customFilterDropdown?: (...args: any[]) => void;
|
customFilterDropdown?: (...args: any[]) => any;
|
||||||
// 兼容 2.x 的 columns slots 配置
|
// 兼容 2.x 的 columns slots 配置
|
||||||
[key: string]: (...args: any[]) => void;
|
[key: string]: (...args: any[]) => any;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type ContextProps = ComputedRef<ContextSlots>;
|
export type ContextProps = ComputedRef<ContextSlots>;
|
||||||
|
|
|
@ -30,7 +30,6 @@ This example shows how to fetch and present data from a remote server, and how t
|
||||||
>
|
>
|
||||||
<template #bodyCell="{ column, text }">
|
<template #bodyCell="{ column, text }">
|
||||||
<template v-if="column.dataIndex === 'name'">{{ text.first }} {{ text.last }}</template>
|
<template v-if="column.dataIndex === 'name'">{{ text.first }} {{ text.last }}</template>
|
||||||
<template v-else>{{ text }}</template>
|
|
||||||
</template>
|
</template>
|
||||||
</a-table>
|
</a-table>
|
||||||
</template>
|
</template>
|
||||||
|
|
|
@ -17,14 +17,13 @@ Simple table with actions.
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<a-table :columns="columns" :data-source="data">
|
<a-table :columns="columns" :data-source="data">
|
||||||
<template #headerCell="{ title, column }">
|
<template #headerCell="{ column }">
|
||||||
<template v-if="column.key === 'name'">
|
<template v-if="column.key === 'name'">
|
||||||
<span>
|
<span>
|
||||||
<smile-outlined />
|
<smile-outlined />
|
||||||
Name
|
Name
|
||||||
</span>
|
</span>
|
||||||
</template>
|
</template>
|
||||||
<template v-else>{{ title }}</template>
|
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<template #bodyCell="{ column, record }">
|
<template #bodyCell="{ column, record }">
|
||||||
|
@ -56,7 +55,6 @@ Simple table with actions.
|
||||||
</a>
|
</a>
|
||||||
</span>
|
</span>
|
||||||
</template>
|
</template>
|
||||||
<template v-else>{{ record.name }}</template>
|
|
||||||
</template>
|
</template>
|
||||||
</a-table>
|
</a-table>
|
||||||
</template>
|
</template>
|
||||||
|
|
|
@ -21,7 +21,6 @@ Add border, title and footer for table.
|
||||||
<template v-if="column.dataIndex === 'name'">
|
<template v-if="column.dataIndex === 'name'">
|
||||||
<a>{{ text }}</a>
|
<a>{{ text }}</a>
|
||||||
</template>
|
</template>
|
||||||
<template v-else>{{ text }}</template>
|
|
||||||
</template>
|
</template>
|
||||||
<template #title>Header</template>
|
<template #title>Header</template>
|
||||||
<template #footer>Footer</template>
|
<template #footer>Footer</template>
|
||||||
|
|
|
@ -24,7 +24,6 @@ Table cell supports `colSpan` and `rowSpan` that set in render return object. Wh
|
||||||
<template v-if="column.dataIndex === 'name'">
|
<template v-if="column.dataIndex === 'name'">
|
||||||
<a href="javascript:;">{{ text }}</a>
|
<a href="javascript:;">{{ text }}</a>
|
||||||
</template>
|
</template>
|
||||||
<template v-else>{{ text }}</template>
|
|
||||||
</template>
|
</template>
|
||||||
</a-table>
|
</a-table>
|
||||||
</template>
|
</template>
|
||||||
|
|
|
@ -22,7 +22,6 @@ Implement a customized column search example via `customFilterDropdown`.
|
||||||
<template v-if="column.key === 'name'">
|
<template v-if="column.key === 'name'">
|
||||||
<span style="color: #1890ff">Name</span>
|
<span style="color: #1890ff">Name</span>
|
||||||
</template>
|
</template>
|
||||||
<template v-else>{{ column.title }}</template>
|
|
||||||
</template>
|
</template>
|
||||||
<template
|
<template
|
||||||
#customFilterDropdown="{ setSelectedKeys, selectedKeys, confirm, clearFilters, column }"
|
#customFilterDropdown="{ setSelectedKeys, selectedKeys, confirm, clearFilters, column }"
|
||||||
|
@ -70,9 +69,6 @@ Implement a customized column search example via `customFilterDropdown`.
|
||||||
<template v-else>{{ fragment }}</template>
|
<template v-else>{{ fragment }}</template>
|
||||||
</template>
|
</template>
|
||||||
</span>
|
</span>
|
||||||
<template v-else>
|
|
||||||
{{ text }}
|
|
||||||
</template>
|
|
||||||
</template>
|
</template>
|
||||||
</a-table>
|
</a-table>
|
||||||
</template>
|
</template>
|
||||||
|
|
|
@ -41,7 +41,6 @@ Table with editable cells.
|
||||||
<a>Delete</a>
|
<a>Delete</a>
|
||||||
</a-popconfirm>
|
</a-popconfirm>
|
||||||
</template>
|
</template>
|
||||||
<template v-else>{{ text }}</template>
|
|
||||||
</template>
|
</template>
|
||||||
</a-table>
|
</a-table>
|
||||||
</template>
|
</template>
|
||||||
|
|
|
@ -24,7 +24,6 @@ Ellipsis cell content via setting `column.ellipsis`.
|
||||||
<template v-if="column.dataIndex === 'name'">
|
<template v-if="column.dataIndex === 'name'">
|
||||||
<a>{{ text }}</a>
|
<a>{{ text }}</a>
|
||||||
</template>
|
</template>
|
||||||
<template v-else>{{ text }}</template>
|
|
||||||
</template>
|
</template>
|
||||||
</a-table>
|
</a-table>
|
||||||
</template>
|
</template>
|
||||||
|
|
|
@ -18,11 +18,10 @@ When there's too much information to show and the table can't display all at onc
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<a-table :columns="columns" :data-source="data" :scroll="{ x: 2000 }">
|
<a-table :columns="columns" :data-source="data" :scroll="{ x: 2000 }">
|
||||||
<template #bodyCell="{ column, text }">
|
<template #bodyCell="{ column }">
|
||||||
<template v-if="column.key === 'action'">
|
<template v-if="column.key === 'action'">
|
||||||
<a>Delete</a>
|
<a>Delete</a>
|
||||||
</template>
|
</template>
|
||||||
<template v-else>{{ text }}</template>
|
|
||||||
</template>
|
</template>
|
||||||
<template #expandedRowRender="{ record }">
|
<template #expandedRowRender="{ record }">
|
||||||
<p style="margin: 0">
|
<p style="margin: 0">
|
||||||
|
|
|
@ -25,11 +25,10 @@ A Solution for displaying large amounts of data with long columns.
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<a-table :columns="columns" :data-source="data" :scroll="{ x: 1500, y: 300 }">
|
<a-table :columns="columns" :data-source="data" :scroll="{ x: 1500, y: 300 }">
|
||||||
<template #bodyCell="{ column, text }">
|
<template #bodyCell="{ column }">
|
||||||
<template v-if="column.key === 'operation'">
|
<template v-if="column.key === 'operation'">
|
||||||
<a>action</a>
|
<a>action</a>
|
||||||
</template>
|
</template>
|
||||||
<template v-else>{{ text }}</template>
|
|
||||||
</template>
|
</template>
|
||||||
</a-table>
|
</a-table>
|
||||||
</template>
|
</template>
|
||||||
|
|
|
@ -26,11 +26,10 @@ To fix some columns and scroll inside other columns, and you must set `scroll.x`
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<a-table :columns="columns" :data-source="data" :scroll="{ x: 1300, y: 1000 }">
|
<a-table :columns="columns" :data-source="data" :scroll="{ x: 1300, y: 1000 }">
|
||||||
<template #bodyCell="{ column, text }">
|
<template #bodyCell="{ column }">
|
||||||
<template v-if="column.key === 'operation'">
|
<template v-if="column.key === 'operation'">
|
||||||
<a>action</a>
|
<a>action</a>
|
||||||
</template>
|
</template>
|
||||||
<template v-else>{{ text }}</template>
|
|
||||||
</template>
|
</template>
|
||||||
</a-table>
|
</a-table>
|
||||||
</template>
|
</template>
|
||||||
|
|
|
@ -19,15 +19,14 @@ Showing more detailed info of every row.
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<a-table :columns="columns" :data-source="data" class="components-table-demo-nested">
|
<a-table :columns="columns" :data-source="data" class="components-table-demo-nested">
|
||||||
<template #bodyCell="{ column, text }">
|
<template #bodyCell="{ column }">
|
||||||
<template v-if="column.key === 'operation'">
|
<template v-if="column.key === 'operation'">
|
||||||
<a>Publish</a>
|
<a>Publish</a>
|
||||||
</template>
|
</template>
|
||||||
<template v-else>{{ text }}</template>
|
|
||||||
</template>
|
</template>
|
||||||
<template #expandedRowRender>
|
<template #expandedRowRender>
|
||||||
<a-table :columns="innerColumns" :data-source="innerData" :pagination="false">
|
<a-table :columns="innerColumns" :data-source="innerData" :pagination="false">
|
||||||
<template #bodyCell="{ column, text }">
|
<template #bodyCell="{ column }">
|
||||||
<template v-if="column.key === 'state'">
|
<template v-if="column.key === 'state'">
|
||||||
<span>
|
<span>
|
||||||
<a-badge status="success" />
|
<a-badge status="success" />
|
||||||
|
@ -52,7 +51,6 @@ Showing more detailed info of every row.
|
||||||
</a-dropdown>
|
</a-dropdown>
|
||||||
</span>
|
</span>
|
||||||
</template>
|
</template>
|
||||||
<template v-else>{{ text }}</template>
|
|
||||||
</template>
|
</template>
|
||||||
</a-table>
|
</a-table>
|
||||||
</template>
|
</template>
|
||||||
|
|
|
@ -22,7 +22,6 @@ selection happens when clicking checkbox defaultly. You can see https://codesand
|
||||||
<template v-if="column.dataIndex === 'name'">
|
<template v-if="column.dataIndex === 'name'">
|
||||||
<a>{{ text }}</a>
|
<a>{{ text }}</a>
|
||||||
</template>
|
</template>
|
||||||
<template v-else>{{ text }}</template>
|
|
||||||
</template>
|
</template>
|
||||||
</a-table>
|
</a-table>
|
||||||
</template>
|
</template>
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import devWarning from '../../vc-util/devWarning';
|
import devWarning from '../../vc-util/devWarning';
|
||||||
|
import { renderSlot } from 'vue';
|
||||||
import type { Ref } from 'vue';
|
import type { Ref } from 'vue';
|
||||||
import type { ContextSlots } from '../context';
|
import type { ContextSlots } from '../context';
|
||||||
import type { TransformColumns, ColumnsType } from '../interface';
|
import type { TransformColumns, ColumnsType } from '../interface';
|
||||||
|
@ -23,10 +24,15 @@ function fillSlots<RecordType>(columns: ColumnsType<RecordType>, contextSlots: R
|
||||||
});
|
});
|
||||||
|
|
||||||
if (contextSlots.value.headerCell && !column.slots?.title) {
|
if (contextSlots.value.headerCell && !column.slots?.title) {
|
||||||
cloneColumn.title = contextSlots.value.headerCell({
|
cloneColumn.title = renderSlot(
|
||||||
|
contextSlots.value,
|
||||||
|
'headerCell',
|
||||||
|
{
|
||||||
title: column.title,
|
title: column.title,
|
||||||
column,
|
column,
|
||||||
});
|
},
|
||||||
|
() => [column.title as any],
|
||||||
|
);
|
||||||
}
|
}
|
||||||
if ('children' in cloneColumn) {
|
if ('children' in cloneColumn) {
|
||||||
cloneColumn.children = fillSlots(cloneColumn.children, contextSlots);
|
cloneColumn.children = fillSlots(cloneColumn.children, contextSlots);
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import classNames from '../../_util/classNames';
|
import classNames from '../../_util/classNames';
|
||||||
import { flattenChildren, isValidElement, parseStyleText } from '../../_util/props-util';
|
import { flattenChildren, isValidElement, parseStyleText } from '../../_util/props-util';
|
||||||
import type { CSSProperties, HTMLAttributes } from 'vue';
|
import type { CSSProperties, HTMLAttributes } from 'vue';
|
||||||
import { defineComponent, isVNode } from 'vue';
|
import { defineComponent, isVNode, renderSlot } from 'vue';
|
||||||
|
|
||||||
import type {
|
import type {
|
||||||
DataIndex,
|
DataIndex,
|
||||||
|
@ -152,15 +152,19 @@ export default defineComponent<CellProps>({
|
||||||
contextSlots.value.bodyCell &&
|
contextSlots.value.bodyCell &&
|
||||||
!column.slots?.customRender
|
!column.slots?.customRender
|
||||||
) {
|
) {
|
||||||
childNode = flattenChildren(
|
const child = renderSlot(
|
||||||
contextSlots.value.bodyCell({
|
contextSlots.value,
|
||||||
|
'bodyCell',
|
||||||
|
{
|
||||||
text: value,
|
text: value,
|
||||||
value,
|
value,
|
||||||
record,
|
record,
|
||||||
index,
|
index,
|
||||||
column: column.__originColumn__,
|
column: column.__originColumn__,
|
||||||
}) as any,
|
},
|
||||||
|
() => [childNode],
|
||||||
);
|
);
|
||||||
|
childNode = flattenChildren(child as any);
|
||||||
}
|
}
|
||||||
/** maybe we should @deprecated */
|
/** maybe we should @deprecated */
|
||||||
if (props.transformCellText) {
|
if (props.transformCellText) {
|
||||||
|
|
Loading…
Reference in New Issue