diff options
author | herbert <herbert.eiselt@highstreet-technologies.com> | 2020-02-01 16:00:00 +0100 |
---|---|---|
committer | KAPIL SINGAL <ks220y@att.com> | 2020-02-02 00:27:16 +0000 |
commit | 05ef023752abdb4f1e072332496dc7c6eaff8965 (patch) | |
tree | e6be03fadda7e715076f16cca27b5d5ecedaa2a3 /sdnr/wt/odlux/framework/src/components/material-table/utilities.ts | |
parent | ff8cf309fba867c2e641ea20c2ddf074fda5e3e5 (diff) |
SDN-R add updated odlux
Updates all odlux framework and app components.
Issue-ID: SDNC-1032
Signed-off-by: herbert <herbert.eiselt@highstreet-technologies.com>
Change-Id: I13c520489fd40d05b7fd5215f5941af6238e9cae
Diffstat (limited to 'sdnr/wt/odlux/framework/src/components/material-table/utilities.ts')
-rw-r--r-- | sdnr/wt/odlux/framework/src/components/material-table/utilities.ts | 26 |
1 files changed, 25 insertions, 1 deletions
diff --git a/sdnr/wt/odlux/framework/src/components/material-table/utilities.ts b/sdnr/wt/odlux/framework/src/components/material-table/utilities.ts index 6e8902c07..74682cd95 100644 --- a/sdnr/wt/odlux/framework/src/components/material-table/utilities.ts +++ b/sdnr/wt/odlux/framework/src/components/material-table/utilities.ts @@ -196,6 +196,29 @@ export function createExternal<TData>(callback: DataCallback<TData>, selectState }).catch(error => new AddErrorInfoAction(error)); }; + const reloadActionAsync = async (dispatch: Dispatch, getAppState: () => IApplicationStoreState) => { + dispatch(new RefreshAction()); + const ownState = selectState(getAppState()); + const filter = { ...ownState.preFilter, ...(ownState.showFilter && ownState.filter || {}) }; + + try { + const result = await Promise.resolve(callback(ownState.page, ownState.rowsPerPage, ownState.orderBy, ownState.order, filter)); + + + if (ownState.page > 0 && ownState.rowsPerPage * ownState.page > result.total) { //if result is smaller than the currently shown page, new search and repaginate + + let newPage = Math.floor(result.total / ownState.rowsPerPage); + + const repaginationResult = await Promise.resolve(callback(newPage, ownState.rowsPerPage, ownState.orderBy, ownState.order, filter)); + dispatch(new SetResultAction(repaginationResult)); + } else { + dispatch(new SetResultAction(result)); + } + } catch (error) { + new AddErrorInfoAction(error); + } + }; + const createPreActions = (dispatch: Dispatch, skipRefresh: boolean = false) => { return { onPreFilterChanged: (preFilter: { [key: string]: string }) => { @@ -258,6 +281,7 @@ export function createExternal<TData>(callback: DataCallback<TData>, selectState createActions: createActions, createProperties: createProperties, createPreActions: createPreActions, - actionHandler: externalTableStateActionHandler + actionHandler: externalTableStateActionHandler, + reloadActionAsync: reloadActionAsync, } }
\ No newline at end of file |