diff --git a/docs/assets/option/en/common/option-important.md b/docs/assets/option/en/common/option-important.md index 196f2db3b..fe0080625 100644 --- a/docs/assets/option/en/common/option-important.md +++ b/docs/assets/option/en/common/option-important.md @@ -3,3 +3,7 @@ #${prefix} container(HTMLElement) Container DOM, requires width. + +#${prefix} clearDOM(boolean) = true + +Whether to clear the container DOM. \ No newline at end of file diff --git a/docs/assets/option/zh/common/option-important.md b/docs/assets/option/zh/common/option-important.md index f780b1e57..056641ad0 100644 --- a/docs/assets/option/zh/common/option-important.md +++ b/docs/assets/option/zh/common/option-important.md @@ -5,3 +5,7 @@ 容器 DOM,需要具有宽。 可放到初始化参数中。 + +#${prefix} clearDOM(boolean) = true + +是否清空容器 DOM。 \ No newline at end of file diff --git a/packages/react-vtable/demo/vite.config.ts b/packages/react-vtable/demo/vite.config.ts index 9026d0f6e..f3d380d55 100644 --- a/packages/react-vtable/demo/vite.config.ts +++ b/packages/react-vtable/demo/vite.config.ts @@ -26,7 +26,8 @@ export default defineConfig({ resolve: { alias: { '@visactor/vtable': path.resolve(__dirname, '../../vtable/src/index.ts'), - '@src': path.resolve(__dirname, '../../vtable/src/') + '@src': path.resolve(__dirname, '../../vtable/src/'), + '@vutils-extension': path.resolve(__dirname, '../../vtable/src/vutil-extension-temp') // ...localConf.resolve?.alias } } diff --git a/packages/react-vtable/src/tables/base-table.tsx b/packages/react-vtable/src/tables/base-table.tsx index 0f6197809..b04c08c3e 100644 --- a/packages/react-vtable/src/tables/base-table.tsx +++ b/packages/react-vtable/src/tables/base-table.tsx @@ -116,15 +116,20 @@ const BaseTable: React.FC = React.forwardRef((props, ref) => { if (hasRecords && props.records) { return { ...props.option, + clearDOM: false, records: props.records }; } - return props.option; + return { + ...props.option, + clearDOM: false + }; } return { records: props.records, ...prevOption.current, - ...optionFromChildren.current + ...optionFromChildren.current, + clearDOM: false // ...tableContext.current?.optionFromChildren } as IOption; }, diff --git a/packages/vtable/src/core/BaseTable.ts b/packages/vtable/src/core/BaseTable.ts index 728ab42a0..4b43e73d6 100644 --- a/packages/vtable/src/core/BaseTable.ts +++ b/packages/vtable/src/core/BaseTable.ts @@ -243,7 +243,8 @@ export abstract class BaseTable extends EventTarget implements BaseTableAPI { canvasHeight, overscrollBehavior, limitMinWidth, - limitMinHeight + limitMinHeight, + clearDOM = true } = options; this.container = container; this.options = options; @@ -349,8 +350,10 @@ export abstract class BaseTable extends EventTarget implements BaseTableAPI { internalProps.theme.isPivot = this.isPivotTable(); if (container) { - //先清空 - // container.innerHTML = ''; + // 先清空 + if (clearDOM) { + container.innerHTML = ''; + } container.appendChild(internalProps.element); this._updateSize(); } else { diff --git a/packages/vtable/src/ts-types/base-table.ts b/packages/vtable/src/ts-types/base-table.ts index f102c5e6c..5e536ea64 100644 --- a/packages/vtable/src/ts-types/base-table.ts +++ b/packages/vtable/src/ts-types/base-table.ts @@ -428,6 +428,8 @@ export interface BaseTableConstructorOptions { columnWidthComputeMode?: 'normal' | 'only-header' | 'only-body'; customConfig?: any; // 部分特殊配置,兼容xTable等作用 + + clearDOM?: boolean; } export interface BaseTableAPI { /** 数据总条目数 */