From 18cc95fa30f20c7a1c6d0c2c1d22fd920798a159 Mon Sep 17 00:00:00 2001 From: tangjinzhou <415800467@qq.com> Date: Thu, 16 Dec 2021 16:01:58 +0800 Subject: [PATCH] fix: table warning for page, close #5029 --- components/table/Table.tsx | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/components/table/Table.tsx b/components/table/Table.tsx index 29f6230f9..8921a8494 100644 --- a/components/table/Table.tsx +++ b/components/table/Table.tsx @@ -35,7 +35,7 @@ import defaultLocale from '../locale/en_US'; import type { SizeType } from '../config-provider'; import devWarning from '../vc-util/devWarning'; import type { PropType } from 'vue'; -import { reactive, ref, computed, defineComponent, toRef, watchEffect, watch } from 'vue'; +import { nextTick, reactive, ref, computed, defineComponent, toRef, watchEffect, watch } from 'vue'; import type { DefaultRecordType } from '../vc-table/interface'; import useBreakpoint from '../_util/hooks/useBreakpoint'; import useConfigInject from '../_util/hooks/useConfigInject'; @@ -465,11 +465,6 @@ const InteralTable = defineComponent< // Dynamic table data if (mergedData.value.length < total!) { if (mergedData.value.length > pageSize) { - devWarning( - false, - 'Table', - '`dataSource` length is less than `pagination.total` but large than `pagination.pageSize`. Please make sure your config correct data with async mode.', - ); return mergedData.value.slice((current - 1) * pageSize, current * pageSize); } return mergedData.value; @@ -478,6 +473,25 @@ const InteralTable = defineComponent< return mergedData.value.slice((current - 1) * pageSize, current * pageSize); }); + watchEffect( + () => { + nextTick(() => { + const { total, pageSize = DEFAULT_PAGE_SIZE } = mergedPagination.value; + // Dynamic table data + if (mergedData.value.length < total!) { + if (mergedData.value.length > pageSize) { + devWarning( + false, + 'Table', + '`dataSource` length is less than `pagination.total` but large than `pagination.pageSize`. Please make sure your config correct data with async mode.', + ); + } + } + }); + }, + { flush: 'post' }, + ); + const expandIconColumnIndex = computed(() => { // Adjust expand icon index, no overwrite expandIconColumnIndex if set. if (expandType.value === 'nest' && props.expandIconColumnIndex === undefined) {