Skip to content

Commit

Permalink
* dtable: support for reseting state in dtable plugin.
Browse files Browse the repository at this point in the history
  • Loading branch information
catouse committed Jul 18, 2024
1 parent 11fc739 commit f39729e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
16 changes: 16 additions & 0 deletions lib/dtable/src/components/dtable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,22 @@ export class DTable extends Component<DTableOptions, DTableState> {
resetState(props?: DTableOptions, init?: boolean) {
this.#options = undefined;
this.#layout = undefined;

props = props || this.props;
const newState: Partial<DTableState> = {};
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) {
Expand Down
1 change: 1 addition & 0 deletions lib/dtable/src/types/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ export type DTablePlugin<T extends DTablePluginTypes = {}, D extends DTablePlugi
i18n?: Record<string, Record<string, string | object>>;
data: (this: PluginTable) => {} & T['data'],
state: (this: PluginTable) => {} & T['state'],
resetState: boolean | ((this: PluginTable, options: Options) => {} & T['state']);
options: (this: PluginTable, options: Options) => Partial<Options>;
footer: Record<string, CustomRenderResultGenerator<[layout: DTableLayout], PluginTable> | CustomRenderResultItem>;
onCreate: (this: PluginTable, plugin: DTablePlugin<T, D>) => void;
Expand Down

0 comments on commit f39729e

Please sign in to comment.