diff --git a/lib/dtable/src/components/dtable.tsx b/lib/dtable/src/components/dtable.tsx index c0f137f3bc..26771b4bbb 100644 --- a/lib/dtable/src/components/dtable.tsx +++ b/lib/dtable/src/components/dtable.tsx @@ -223,6 +223,22 @@ export class DTable extends Component { resetState(props?: DTableOptions, init?: boolean) { this.#options = undefined; this.#layout = undefined; + + props = props || this.props; + const newState: Partial = {}; + this.#plugins.forEach(plugin => { + const {resetState, state: pluginState} = plugin; + if (resetState) { + if (typeof resetState === 'function') { + Object.assign(newState, resetState.call(this, props)); + } else if (pluginState) { + Object.assign(newState, pluginState.call(this)); + } + } + }); + if (Object.keys(newState).length) { + this.setState(newState); + } } on(event: string, callback: DTableEventListener, target?: DTableEventTarget) { diff --git a/lib/dtable/src/types/plugin.ts b/lib/dtable/src/types/plugin.ts index a72165bf13..8859aa0a38 100644 --- a/lib/dtable/src/types/plugin.ts +++ b/lib/dtable/src/types/plugin.ts @@ -66,6 +66,7 @@ export type DTablePlugin>; data: (this: PluginTable) => {} & T['data'], state: (this: PluginTable) => {} & T['state'], + resetState: boolean | ((this: PluginTable, options: Options) => {} & T['state']); options: (this: PluginTable, options: Options) => Partial; footer: Record | CustomRenderResultItem>; onCreate: (this: PluginTable, plugin: DTablePlugin) => void;