AdapTable State Persistence Guide

Summary

  • By default, AdapTable State is saved to local storage and users need to do anything
  • In practice most users use remote storage which AdapTable provides via a series of functions in State Options

AdapTable State is designed to be persisted allowing for a seamless user experience between sessions.

Local Storage

By default, AdapTable State is stored in the browser's local storage.

This is done using the unique adaptableStateKey property provided in Adaptable Options.

Caution

If using Local Storage, all user state will be lost each time the user clear's the browser cache or switches computers

In practice, very few production users of AdapTable use local storage as their storage mechanism.

Find Out More

Learn more about setting the adaptableStateKey property in the Integration Guide

Remote Storage

AdapTable also enables User State to be persisted remotely in - and subsequently retrieved from - any location of the users' choice.

Note

  • Most of the demos in this site use Local Storage for convenience sake
  • However, the overwhelming majority of real world applications that use AdapTable leverage remote storage

Remote storage is accessible via a set of JavaScript functions available in State Options.

State Options provides 5 functions which allow developers to control the management of AdapTable State and supports custom implementations and functionality for managing state:

Hint

  • This allows you to provide your own hydration or rehydration functionality if required
  • It also allows you to enrich the State when its being loaded with your own items (e.g. Entitlements)
FunctionEnablesDefault AdapTable Behaviour
loadStateCustomization of State loadingLoads State from local storage
applyStateHooking into State hydration
saveStateCustomization of State that is about to be persisted
persistStateCustomisation of State persistencePersists State to local storage
clearStateClears all User StateClears State from local storage

Remote Storage Workflow

The AdapTable State flow is as follows:

  1. User Loads Page --> loadState() state1 -> applyState(state1)
  2. state2 ---- ADAPTABLE NOW READY WITH STATE (state2)
  3. User Updates State ------ saveState(state3):
  4. state4 -> persistState(state4)
AdaptableState Sequence Diagram
AdaptableState Sequence Diagram

Load State

loadState

Default: Loads State from local storage
Manages loading remote Adaptable State (async)

Apply State

applyState

Allows hooking into Adaptable State hydration

Save State

Allows customization of the Adaptable State about to be persisted

Persist State

persistState

Default: Persists State to local storage
Enables the customization of State persistence

Clear State

Allows clearing of remote Adaptable State
Remote State Persistence
Fork
  • This example illustrates how straightforward is to load/persist state from/to a remote datastore
  • Here we use Supabase as our persistence layer
  • We provide custom implementations for loadState and persistState from State Options
Try It Out
  • make any changes to the AdapTable State (e.g. change the current Layout) and then refresh the page: the changes will be retained
  • change the AdaptableStateKey: the grid will be reset to its initial state and a new state will be persisted
  • going back to the previous AdaptableStateKey will restore the previous state

Debouncing State Changes

By default AdapTable will debounce saveState and persistState function calls for 400 miliseconds.

This enables grouping multiple sequential calls into single one.

Note

A good analogy might be how lift / elevator doors work

This can be changed using the debounceStateDelay property in State Options.

debounceStateDelay

Default: 400
boolean
Delay (in ms) to debounce saveState and persistState calls

Managing Multiple States

Load & persist state based on user identity/role
Fork
  • This example shows how to load & persist state based on user identity/role; (the persistence uses Supabase, but any storage provider works (e.g. Firebase, AWS S3, etc.).
  • It also showcases user specific Permissions (Entitlements) and how to use them to control access to AdapTable features.
  • The demo showcases 3 different users:
    • Guest (not logged in)
      • any changes they make will not be persisted and will be lost when the page is refreshed
      • all AdapTable features are available but only in read-only mode
    • Alice
      • any changes she makes will be persisted and will be available only to her
      • all AdapTable features are available and editable, except for the StyledColumn module which is in read-only mode
    • Bob
      • any changes he makes will be persisted and will be available only to him
      • all AdapTable features are available and editable, except for the Alert module which is hidden
  • The logged in users (Alice and Bob) can revert to the Initial Adaptable State by clicking the Reset State button in the Dashboard.

Expand to see how the State Management and Entitlements is configured

Try It Out
  • Log in as Alice or Bob to see how the state is persisted distinctively for each user by making various changes to the grid and then refreshing the page
    • e.g. change the current Layout (sorting/adding/hiding columns), add a new FormatColumn, etc.
  • Reset the state by clicking the Reset State button in the Dashboard at any time
  • Navigate to the StyledColumn module and try to edit the existing style (only Alice will not be able to do this)

Controlling State Persistence

In more advanced use cases, developers wish to control how and when State is persisted.

Their aim is to suppress automatic State Persistence, and to persist state imperatively instead.

There are 2 common scenarios:

  • suppressing all State Persistence and replacing it with an imperative save function

  • suppressing specific State Persistence and replacing just that with an imperative save function

    Hint

    A popular use case is to save Layouts manually, on clicking a button, rather than automatically

Suppressing all Persistence

Persisting state imperatively
Fork
  • In this example we show how to suppress the automatic state persistence and imperatively persist the state
  • This is useful when you want to control when the state is persisted, e.g. after a user action or a specific event
  • This demo uses the Adaptable Context to handle the interaction, but you can use any other mechanism, including your own application logic/state management
Try It Out
  • Perform any changes to the AdapTable State: e.g. change the current Layout (sorting/adding/hiding columns), add a new FormatColumn, etc.
  • The changes will be kept client side and will be persisted only when you click the Persist State button in the Dashboard
  • Refreshing the demo will load the last persisted state, but any changes made since the last persistence will be lost
  • The suppressed changes are logged in the console
  • Reset the state to the initial value by clicking the Reset State button in the Dashboard at any time

Suppressing specific Persistence

Persisting specific state slices imperatively
Fork
  • In this example we show how to suppress the automatic state persistence of specific state slices (e.g. only Layouts with a specific Tag) and imperatively persist them
  • All other state changes will be persisted automatically as usual
  • This is useful when you want to control when specific changes are persisted, e.g. Layout changes, but not other changes (e.g. FormatColumns)
  • This demo uses the Adaptable Context to handle the interaction, but you can use any other mechanism, including your own application logic/state management
Try It Out
  • Perform any changes to the 'Protected Layout': e.g. sort/filter/hide columns, etc.
    • All changes will NOT be persisted automatically but only when you click the Persist State button in the Dashboard
    • Refreshing the demo will load the last persisted state, but any changes made since the last persistence will be lost
    • The suppressed changes are logged in the console
  • Perform any changes to the 'Standard Layout': e.g. sort/filter/hide columns, etc.
    • All changes will be persisted automatically as usual
  • Any other changes to the AdapTable State will be persisted automatically as usual
  • Reset the state to the initial value by clicking the Reset State button in the Dashboard at any time