Providing Initial Adaptable State
Summary
- AdapTable instances are pre-populated at Design Time with Initial Adaptable State
- These are the objects that Users require for first time use
- When Adaptable loads, the Initial State is saved into Adaptable State
- The contents of this Initial State is arranged by Module and consist of both:
- individual properties
- collections of AdapTable Objects
Find Out More
See the list of Initial State sections in Initial Adaptable State Reference
Developers will populate each new AdapTable instance with initial Adaptable State.
This means that when end-users open the new application for the first time, they won't just seen a clean AG Grid instance but, rather, one pre-loaded with multiple Layouts, Searches, Styles, Edit Rules, Reports etc.
Note
- Initial State constitutes those objects which can (and will) be overridden at run-time and saved by user's actions
- Anything which cannot be changed at run-time is provided through Adaptable Options
This enables a grid to be provided that matches users needs, allowing them to be productive immediately.
The Initial State is then merged into Adaptable State and can be added or edited (if the user's Entitlements allow) and persisted (either locally or remotely) using AdapTable's State Management.
Caution
- As the name implies Initial State should only be used for first-time use of the Application
- AdapTable State should be relied on to manage all subsequent state-related behaviour
Breaking Change
- We try hard to ensure that all changes to the
InitialStateobject are fully backwardly compatible - Where this is not possible we provide Automatic Adaptable State Migration to ease the transition
The Basics
Initial State is a JSON object created at design-time.
It consists of a series of (nullable) properties that themselves each implement the BaseState class.
Most of the contents of each section are collections of Adaptable Objects (e.g. Layouts) but can also be string properties (e.g name of the Current Layout).
It is provided to AdapTable via the initialState property in the base section of Adaptable Options.
initialState
Note
Initial Adaptable State can be provided either as pure JSON or a url string to a file containing the JSON
How It Works
When AdapTable is first loaded, the Initial Adaptable State is read into memory and then stored.
Note
This storage can be locally or remotely depending on the AdapTable State Persistence
During that initial session AdapTable will merge the Initial Adaptable State with any user state that was created.
Subsequently, each time the application is launched, that User State is retrieved and the particular AdapTable instance is pre-populated with it.
Hint
Although you can construct Inital State by hand, its often easier when building "complex" items like Grid Filter to create them in the GUI at design time and then copy and paste the resulting state
Updating Initial Adaptable State
As the name implies, the concept behind Initial Adaptable State is that it provides - at design-time - the objects, entitlements and theme for initial use of the Application.
It is read once and merged into the user's Adaptable State, and then any run-time changes which users make will form part of their State and be continually updated.
But sometimes, after the application has gone live, developers might want to update one section in Initial Adaptable State while ensuring that the rest of the user's State remains untouched.
Revision Property
This can be accomplished through the Revision property in BaseState
Note
BaseState is the base interface for all User State sections
The Revision property is defined as follows:
Revision?: number | { Key: number; UpdateStrategy: 'Override' | 'KeepUserDefined' };Replacing an Entire Section
As can be seen the Revision object can, in its simplified form, be a number.
In this scenario, if you increment (or provide from new) the revision number in a section of Initial State, AdapTable will replace that section (but only that section) in the user's State with the new InitialState.
Caution
Providing a number is replace only with no merging taking place
export default {
CustomSort: {
// This replaces existing Custom Sort section in User State with section provided here
// (if the Revision Number - of 2 - is higher than the one currently in User State)
// All other sections of Initial Adaptable Stateg will remain untouched
Revision: 2,
CustomSorts: [
{
Name: 'CustomSort-Rating',
ColumnId: 'Rating',
SortedValues: ['AAA', 'AA+', 'AA', 'AA-'], // etc.
},
],
},
} as InitialState;Updating Part of a Section
For a more granular approach you can provide an object which contains 2 properties:
Keyof type numberUpdateStrategywhich can have 2 values:Override- the provided Initial State will override whatever is stored in AdapTable State for that sectionKeepUserDefined- the provided Initial State will be added to what is stored in Adaptable State
export default {
CustomSort: {
// This adds a new item to the Custom Sort section of User State
// The UpdateStrategy property is set to 'KeepUserDefined' (rather than 'Override')
// so any user-created items in Custom Sort will not be replaced
Revision: {Key: 5, UpdateStrategy: 'KeepUserDefined'},
CustomSorts: [
{
Name: 'CustomSort-Rating',
ColumnId: 'Rating',
SortedValues: ['AAA', 'AA+', 'AA', 'AA-'], // etc.
},
],
},
} as InitialState;Providing Custom Data
The Application State section of Adaptable State contains an ApplicationDataEntries array.
This is essentially a set of key / value pairs that you can populate with any data that you want and which AdapTable will store in its state.
Hint
This is a useful way to store additional data with your Initial Adaptable State e.g. user location, last updated time etc.
Adaptable Objects
All objects in Initial Adaptable State inherit from AdaptableObject.
Note
- AdapTable Objects comprise most of the objects supplied in Initial Adaptable State like Format Column
- However it also includes those objects which appear as Initial State properties (e.g. Adaptable Style, Button etc.)
Adaptable Object Properties
The AdaptableObject is defined as follows:
| Property | Description |
|---|---|
| AdaptableVersion | Current AdapTable version |
| IsReadOnly | Sets Entity to ReadOnly (overwriting a Strategy Entitlement of 'Full') |
| Metadata | Optional metadata associated with the object; can be used to store additional information or configuration |
| Source | Source of state object: 'InitialState' if provided via AdaptableOptions.initialState, 'User' or undefined for runtime state |
| Tags | List of Tags associated with the Object; often used for extending Layouts |
Uuid
The Uuid property is of type TypeUuid and used for easy identification of objects.
It allows AdapTable instances to share state and inform each other of CRUD events on an item.
Hint
If Team Sharing is enabled, any Adaptable Object can easily be shared at run-time between colleagues
Caution
- Do not set this property when writing objects in Initial Adaptable State
- Instead, it will be set by AdapTable at run-time when the Initial State is first read
IsReadOnly
Entitlements in AdapTable typically operate at the Module level.
Hint
Each Module can be set to be Full, ReadOnly or Hidden
However, sometimes a use case demands that while the Module has a 'Full' entitlement (i.e. it is editable), one particular object must be ReadOnly (i.e. cannot be deleted).
This property is designed for precisely this reason, and it will overrride the 'Full' Entitlement in the Module.
Note
- There is no property for the opposite use case
- You cannot change an AdapTable object to be
Fullwhere the Module's Entitlement isReadOnly
Source
The Source property is applied by AdapTable and defines where the object was first created.
Caution
Do not provide a value for this property in Initial Adaptable State as it will be set by AdapTable at run-time
AdapTable will dynamically set this property to be one of 2 values:
InitialState- the object was initially provided in Initial Adaptable StateUser- the object was created by the user at run-time in the AdapTable UI
Note
If an object is first supplied in Initial State and then later amended by the User in the UI, the value of the Source property will remain unchanged
Object Tags
Every Adaptable Object has a Tags property (of type AdaptableObjectTag).
A Tag is a very simple object that just contains a string value.
However it allows you to provide additional information to any object that you create.
Hint
- The main use case of Tags is to limit the scope of the Object to particular Layouts
- See Extending Layouts for full instructions how to achieve this
Object Meta Data
Every Adaptable Object has a MetaData property.
This is designed to allow developers to assign custom properties / data to the object.
Hint
This is most commonly used to additional extra information to Layouts (e.g. team)
AdaptableVersion
Every Adaptable Object states which version of AdapTable is being run.
This is useful if you have multiple applications running, using different AdapTable versions.
Suspending Objects
To DO - go to link
FAQ
What are Adaptable Objects An Adaptable Object is an object created either by the user at run-time, or by developers at design-time, which are used by Adaptable Modules. Export, Format Columns, Shortcuts, Alerts etc. are all Adaptable Objects.
Is it possible to create our own Adaptable Objects? Yes it is and we expect you to. All Adaptable Objects are simple JSON objects so you can easily create your own objects in Initial Adaptable State and then you can include them in the application.
What do Adaptable Objects look like?
Obviously all Adaptable Objects are different but they do all implement a common Adaptable Object interface which has just a few basic properties useful to all objects (e.g. Uuid).
Are we only able to save Adaptable Objects we create to the local browser cache? No - you can save AdapTable objects to any remote location of your choice by using the State Options functions.
Can we turn off an AdapTable Object without having to subsequently re-create it?
Yes, Adaptable Objects all have an IsSuspended property which when sets to true, prevents the Object from being used, while keeping it in Adaptable State.
How do I know when an Adaptable Object has changed? By listening to the Adaptable State Changed Event