Extending Layouts

Summary

  • Layouts contain useful sets of column-related information
  • This means that they do not include Formats, Alerts and Reports etc
  • AdapTable provides a mechanism for users who find this restriction too constraining
  • Object Tags allow particular objects (e.g Formats) to be grouped with certain Layouts

At their core, Layouts are simply sets of column-related properties.

They contain details of Column visibility, order, sorting, grouping, aggregations, filters and related properties.

Caution

By default, Layouts do not contain other Adaptable Objects like styling, formatting, Alerts or Flashing Cells

This results in 2 types of "restrictions":

  • all Adaptable Objects in Adaptable State are automatically available in all Layouts, even though a user might prefer, for example, for some styles or Alerts to be applicable to one Layout but not another

  • developers cannot add custom objects, or properties, to their Layouts

AdapTable therefore allows for Layouts to be extended to meet these 2 limitations:

  • object tags - so that some additional AdapTable objects are "included" in the Layout

  • metadata - to enable developers to provide additional bespoke information in the Layout

AdapTable Objects

AdapTable allows Layouts to be extended to have knowledge of specific Adaptable Objects.

In other words developers can specify that a particular Report or Format Calculated Column is available in LayoutA but not LayoutB.

Object Tags

AdapTable Objects are extended into Layouts by using Object Tags.

Object Tags are available to AdapTable Objects in these Modules:

ModuleExtendable Object
AlertsAlertDefinition
Custom SortCustomSort
Flashing CellFlashingCellDefinition
Column FormattingFormatColumn
FreeText ColumnFreeTextColumn
Plus MinusPlusMinusNudge
SchedulesReportSchedule & ReminderSchedule
ShortcutsShortcut
Styled ColumnsStyledColumn

This approach leverages the Tags property, which exists in every Adaptable Object, to list all the Layouts where the Object can be used - ideal for our purposes.

Deep Dive

Understanding Object Tags

Hint

Because this is such a popular use case, the layoutTagOptions section of Layout Options contains a number of properties designed to help developers easily achieve this - see below for more details

Extended Layouts
Fork
  • This demo illustrates how to leverage the tags property in Adaptable Objects to limit their scope to particular Layouts.
  • We provide 2 Layouts - First Layout and Second Layout with identical configuration
  • We also provide 5 Format Columns and 5 Styled Columns - all are given a Tag with the name of a Layout:
  • There are 5 Format Columns provided:
    • License is bold - First Layout
    • Language is blue where value is 'TypeScript' - First Layout
    • Github Stars has a bespoke Style and a Display Format - Second Layout
    • Whole row is orange where Language value is 'HTML' - Second Layout
    • Date Columns are Italicised and have a Display Format - First Layout and Second Layout
  • Additionally we provide 5 Styled Columns:
    • Name has a Badge Style - First Layout
    • Open PRs has a Gradient Column - First Layout
    • Closed Issues has a Percent Bar - Second Layout
    • History has a different Sparkline Column in First Layout and Second Layout
  • We set 2 properties to true in the layoutTagOptions section of Layout Options to facilitate this:
    • autoCheckTagsForLayouts - tells a Layout to check all Objects to see if they include a Tag that matches its Name
    • autoGenerateTagsForLayouts - tells AdapTable to automatically add all Layouts to the Tags collection so they are visible in the UI

Expand to see the how the Object Tags are applied

Try It Out
  • Switch between the 2 Layouts to see the different Format Columns and Styled Columns applied
  • Edit one of the objects to change the Tags it contains and see how that affects the Layout

Configuring Object Tags

Developers are able to set up Object Tags in AdapTable in order to extend Layouts.

Developer Guide

Setting up Object Tags to Extend Layouts

There are the steps required to extend Layouts by leveraging Object Tags:

const adaptableOptions: AdaptableOptions = {
  layoutOptions: {
    layoutTagOptions: {
      autoGenerateTagsForLayouts: true,
      autoCheckTagsForLayouts: true,
    },
  },
};
1
Set Auto Generate Tags for Layouts to true

Set autoGenerateTagsForLayouts in layoutTagOptions section of Layout Options) to true.

AdapTable will create an Object Tag entry for every Layout.

const adaptableOptions: AdaptableOptions = {
  layoutOptions: {
    layoutTagOptions: {
      autoGenerateTagsForLayouts: true,
      autoCheckTagsForLayouts: true,
    },
  },
};
2
Set Auto Check for Layouts to true

Set autoCheckTagsForLayouts in layoutTagOptions section of Layout Options) to true.

AdapTable will now check if an Object's Tags are available in the current Layout (i.e. include Layout name)

Layout: {
    CurrentLayout: 'First Layout',
    Layouts: [
      {
        TableColumns: ['name', 'language', 'description'],
        Name: 'First Layout',
      },
      {
        TableColumns: ['license', 'has_wiki', 'has_pages'],
        Name: 'Second Layout',
      },
    ],
  },
3
Create the Layout(s)

Define any required Layout(s) in Layout Initial State.

Create the Layouts as usual - nothing special is required.

FormatColumn: {
  FormatColumns: [
    {
      Name: 'FormatColumn-name-270',
      Scope: { ColumnIds: ['name'] },
      Style: { FontWeight: 'Bold' },
      Tags: ['First Layout'],
    },
    {
      Name: 'FormatColumn-text-271',
      Scope: { ColumnIds: ['text'] },
      Style: { FontStyle: 'Italic', },
      Tags: ['First Layout', 'Second Layout'],
    },
  ],
}
4
Add the Layout Names to Object Tags in Other Objects

Create other Initial Adaptable State as needed.

Add a Tags property to each Object that you wish to scope to a given Layout (or Layouts) only.

Provide the name of the Layout(s) as an array to the property.

Using Object Tags

End Users are also able to manage Layouts using Object Tags.

If Tags have been provided, each Object's Creation Wizard will include an additional step called 'Tags'.

This lists all the Tags which have been provided, together with a Checkbox.

Ticking the Checkbox will limit the scope of the Object just to the checked Layouts.

Layout Tag Options

Three properties in the layoutTagOptions section of Layout Options aid in the creation of Object Tags:

autoCheckTagsForLayouts

Boolean
AdapTable Automatically checks if an Adaptable Object's Tags are available in the current Layout

autoGenerateTagsForLayouts

Boolean | function
Whether AdapTable should create an Object Tag for every Layout

isObjectExtendedInLayout

Boolean function
Checks if the provided Adaptable Object is available in the given Layout

Creating Extended Layouts

The createOrUpdateExtendedLayout function in Layout API enables creating or updating Extended Layouts.

createOrUpdateExtendedLayout

extendedLayout: ExtendedLayout
void
Receives an Extended Layout and saves it, and all extended Objects, to State

Retrieving Extended Layouts

AdapTable also provides the getExtendedLayoutByName helper function in Layout API which can fetch an Extended Layout from AdapTable State.

Hint

This is particularly useful if wanting to share or clone an Extended Layout (see below)

getExtendedLayoutByName

layoutName: string
ExtendedLayout
Returns the full Extended Layout object with the given name

Sharing Extended Layouts

By their nature, Extended Layouts are not stored as a single, composite object in Adaptable State.

Instead, the main properties are in the Layout object, but extended objects (e.g. Format Columns or Custom Sorts) are stored in the appropriate State section.

This means that it is not possible, easily, to share an Extended Layout as a single object.

However by using the 2 functions above - getExtendedLayoutByName and createOrUpdateExtendedLayout - it is possible to fetch an ExtendedLayout and make any changes to it as needed.

Hint

A better way to do this is via Referenced Team Sharing which allows a Layout to be shared between team members

Sharing Extended Layouts
Fork
  • This example has an initial Layout ('First Layout') extended with 4 Format Columns
  • A Custom Dashboard Button imports - and sets - a new Extended Layout ('Extended Layout') with 2 Styled Columns
  • When a Layout is Selected we send a System Status message with its contents (and log the full object to the console())
Try It Out
  • Click the button to import and set the new Extended Layout and note that you see the Layout and the 2 Styled Columns
  • Open the System Status popup to see the contents of the Extended Layout
  • Open the Console and switch between Layouts to see the full Extended Layout object

Cloning Extended Layouts

Extended Layouts, like regular Layouts, can be be cloned.

AdapTable will clone the underlying Layout and all the objects that are being extended (e.g. Format Columns or Styled Columns).

This is done using the cloneExtendedLayout function in Layout API.

cloneExtendedLayout

layout: ExtendedLayout, newName: string
ExtendedLayout
Clones an Extended Layout

Caution

  • Both original and cloned Layouts will now reference the same extended objects
  • This means that changing that object (e.g. a Format Column) will be reflected in both Layouts
Cloning Extended Layouts
Fork
  • This example has an Extended Layout ('Original Layout') which we clone
Try It Out
  1. Click first the button to clone (and then set) the Extended Layout and note that all extended objects have been cloned
  2. Click the second button (which becomes enabled) to change the style for the Language Column
  3. Switch Layouts and note that you see the new style in the original Layout also

Meta Data

Sometimes developers want to extend Layouts by including their own custom bespoke properties and objects.

Note

A common use case is to include the Author or the Team or other organisation-specific details

This is done by using the Metadata property (of type any) which is in the Adaptable Object type, from which the Layout object derives.

Caution

Unlike most properties in the Layout, MetaData can only be added at design-time or programatically

Layouts With Metadata
Fork
  • This example shows how to use Layout Meta data. We add a Metadata property to 4 layouts:
    • First Layout and Third Layout - have Metadata property of 'Large' - and they show the Dashboard, open the Tool Panel and use dark theme
    • Second Layout and Fourth Layout - have Metadata property of 'Small' - and they hide the Dashboard, close the Tool Panel and use light dark theme
Try It Out
  • Switch between the Layouts (you might need to use the status bar when the Dashboard is hidden!) to see how we listen to MetaData and change the grid accordingly