Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: 添加emptyContent属性 #1348

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions examples/table/table.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ columns | Array | [] | 列配置,泛型 T 指表格数据类型。TS 类型:
data | Array | [] | 数据源,泛型 T 指表格数据类型。TS 类型:`Array<T>` | N
disableDataPage | Boolean | false | 是否禁用本地数据分页。当 `data` 数据长度超过分页大小时,会自动进行本地数据分页。如果 `disableDataPage` 设置为 true,则无论何时,都不会进行本地数据分页 | N
empty | String / Slot / Function | '' | 空表格呈现样式,支持全局配置 `GlobalConfigProvider`。TS 类型:`string | TNode`。[通用类型定义](https://github.com/Tencent/tdesign-vue-next/blob/develop/src/common.ts) | N
emptyContent | String | '-' | 表格内容为空时展现的字符串 | N
firstFullRow | String / Slot / Function | - | 首行内容。TS 类型:`string | TNode`。[通用类型定义](https://github.com/Tencent/tdesign-vue-next/blob/develop/src/common.ts) | N
fixedRows | Array | - | 固定行(冻结行),示例:[M, N],表示冻结表头 M 行和表尾 N 行。M 和 N 值为 0 时,表示不冻结行。TS 类型:`Array<number>` | N
footData | Array | [] | 表尾数据源,泛型 T 指表格数据类型。TS 类型:`Array<T>` | N
Expand Down
5 changes: 5 additions & 0 deletions src/table/base-table-props.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ export default {
type: [String, Function] as PropType<TdBaseTableProps['empty']>,
default: '',
},
/** 表格内容为空时展现的字符串 */
emptyContent: {
type: [String, Function] as PropType<TdBaseTableProps['emptyContent']>,
default: '-',
},
/** 首行内容 */
firstFullRow: {
type: [String, Function] as PropType<TdBaseTableProps['firstFullRow']>,
Expand Down
16 changes: 15 additions & 1 deletion src/table/base-table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
onMounted,
} from 'vue';
import pick from 'lodash/pick';
import forIn from 'lodash/forIn';
import props from './base-table-props';
import useTableHeader from './hooks/useTableHeader';
import useColumnResize from './hooks/useColumnResize';
Expand Down Expand Up @@ -152,7 +153,7 @@ export default defineComponent({
};

const { type, rowHeight, bufferSize = 20, isFixedRowHeight = false } = props.scroll || {};
const { data } = toRefs<any>(props);
const { data, emptyContent } = toRefs<any>(props);
const {
trs = null,
scrollHeight = null,
Expand Down Expand Up @@ -267,6 +268,19 @@ export default defineComponent({
render() {
const { rowAndColFixedPosition } = this;
const data = this.isPaginateData ? this.dataSource : this.data;

/**
* 判断空数据逻辑
*/
// 遍历每一行的数据
for (let i = data.length; i--; ) {
// 遍历每一列的数据
forIn(data[i], (value, key) => {
if (value === undefined || value === null || value === '') {
data[i][key] = this.emptyContent;
}
});
}
const columns = this.spansAndLeafNodes?.leafColumns || this.columns;

const defaultColWidth = this.tableLayout === 'fixed' && this.isWidthOverflow ? '100px' : undefined;
Expand Down
1 change: 1 addition & 0 deletions src/table/tbody.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export const extendTableProps = [
'rowAttributes',
'loading',
'empty',
'emptyContent',
'fixedRows',
'firstFullRow',
'lastFullRow',
Expand Down
5 changes: 5 additions & 0 deletions src/table/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ export interface TdBaseTableProps<T extends TableRowData = TableRowData> {
* @default ''
*/
empty?: string | TNode;
/**
* 表格内容为空时展现的字符串
* @default '-'
*/
emptyContent?: string;
/**
* 首行内容
*/
Expand Down