Skip to content

Commit

Permalink
feat: add clearDOM config
Browse files Browse the repository at this point in the history
  • Loading branch information
Rui-Sun committed May 13, 2024
1 parent 3a4dcd1 commit 5013c03
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 6 deletions.
4 changes: 4 additions & 0 deletions docs/assets/option/en/common/option-important.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,7 @@
#${prefix} container(HTMLElement)

Container DOM, requires width.

#${prefix} clearDOM(boolean) = true

Whether to clear the container DOM.
4 changes: 4 additions & 0 deletions docs/assets/option/zh/common/option-important.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,7 @@
容器 DOM,需要具有宽。

可放到初始化参数中。

#${prefix} clearDOM(boolean) = true

是否清空容器 DOM。
3 changes: 2 additions & 1 deletion packages/react-vtable/demo/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down
9 changes: 7 additions & 2 deletions packages/react-vtable/src/tables/base-table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -116,15 +116,20 @@ const BaseTable: React.FC<Props> = 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;
},
Expand Down
9 changes: 6 additions & 3 deletions packages/vtable/src/core/BaseTable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 2 additions & 0 deletions packages/vtable/src/ts-types/base-table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,8 @@ export interface BaseTableConstructorOptions {
columnWidthComputeMode?: 'normal' | 'only-header' | 'only-body';

customConfig?: any; // 部分特殊配置,兼容xTable等作用

clearDOM?: boolean;
}
export interface BaseTableAPI {
/** 数据总条目数 */
Expand Down

0 comments on commit 5013c03

Please sign in to comment.