# Referenced Team Sharing

Canonical page: https://www.adaptabletools.com/docs/handbook-team-sharing-referenced

- Referenced Team Sharing ensures that complex Shared Entities are fully shareable
- Not only is the object shared but so are any dependent objects (e.g. Calculated Column in a Layout)
- When sharing an Extended Layout all objects extended into that Layout are included in the Share

Sometimes when using [Team Sharing](https://www.adaptabletools.com/docs/handbook-team-sharing/index.md), a Shared Entity might contain references to other objects.

When this happens, AdapTable will:
- find all the associated dependencies
- upload them into Team Share together with the main Shared Entity

### How Referenced Sharing Works

AdapTable performs referenced sharing automatically.

It is able to handle transitive dependencies which can be multiple levels deep.

For example, if a shared Layout included a Calculated Column with a BooleanExpression which referenced a Named Query which itself referenced another Named Query, then all 4 objects would be uploaded to Team Share.

Similarly if objects have been [extended into](https://www.adaptabletools.com/docs/handbook-layouts-extending/index.md) a shared Layout then these Objects will also be uploaded to the Team Share.

If the Sharing is **Active** and the uploaded Shared Entity has dependencies, these will all be Active as well

## Sharing Objects

The most common referencing use case is when one [Adaptable Object](https://www.adaptabletools.com/docs/dev-guide-adaptable-state-initial-state/index.md#adaptable-objects) references a second AdapTable Object.

For instance sharing a [Format Column](https://www.adaptabletools.com/docs/handbook-column-formatting/index.md) which references a [Named Query](https://www.adaptabletools.com/docs/handbook-named-queries/index.md).

AdapTable will ensure that all dependencies are shared.

**Example: Referenced Team Sharing: Adaptable Objects**

Team Sharing with Adaptable Objects

- This demo illustrates Referenced Sharing of AdapTable Objects:
- **Alice** has 2 related objects:
  - a Named Query called `Hottest JavaScript`
  - a Format Column which references the Named Query to style rows that match

- As **Alice** share the Format Column
- Switch to **Bob** and open TeamShare
- You will note that not only is the Format Column there but so is the Named Query which it references

Demo project (Vanilla); the files without a marker are shown below:

```text
src/
  adaptableOptions.ts
  agGridModules.ts     [template]
  columnDefs.ts        [template]
  gridOptions.ts       [template]
  index.ts
  onAdaptableReady.ts
  rowData.ts           [template]
  styles.css           [template]
index.html             [template]
package.json           [template]
tsconfig.json          [template]
```

Files marked `[template]` are the same in every demo; see the [demo template](https://www.adaptabletools.com/llms/demo-template.md#vanilla).

**`src/adaptableOptions.ts`**

```ts
import {AdaptableOptions, InitialState} from '@adaptabletools/adaptable';
import {WebFramework} from './rowData';

// use a common Team Sharing state key for both users
const TEAM_SHARING_STATE_KEY = 'ReferencedObjectsTeamSharing_TeamSharingState';
export const getAdaptableOptionsForUser = (
  userName: 'Alice' | 'Bob',
  updateCurrentUser: (userName: 'Alice' | 'Bob') => void
): AdaptableOptions<WebFramework> => {
  const commonInitialState: InitialState = {
    Dashboard: {
      Revision: Date.now(),
      Tabs: [
        {
          Name: 'Select Current User',
          Toolbars: ['CurrentUser', 'Layout'],
        },
      ],
      ModuleButtons: ['FormatColumn', 'TeamSharing'],
    },
    Layout: {
      CurrentLayout: 'Standard Layout',
      Layouts: [
        {
          TableColumns: [],
          Name: 'Standard Layout',
        },
      ],
    },
  };
  const userSpecificInitialState: InitialState =
    userName === 'Alice'
      ? {
          StatusBar: {
            StatusBars: [
              {
                Key: 'Center Panel',
                StatusBarPanels: ['FormatColumn', 'TeamSharing'],
              },
            ],
          },
          FormatColumn: {
            FormatColumns: [
              {
                Name: 'formatColumn-all',
                Style: {
                  BackColor: '#8fd3fe',
                },
                Scope: {
                  All: true,
                },
                Rule: 'QUERY("Hottest JavaScript") ',
              },
            ],
          },
          NamedQuery: {
            NamedQueries: [
              {
                Name: 'Hottest JavaScript',
                Expression:
                  '[language]="JavaScript" AND ([github_watchers] > 2000 OR [github_stars] > 14500)',
              },
            ],
          },
          Layout: {
            CurrentLayout: 'Standard Layout',
            Layouts: [
              {
                TableColumns: [
                  'name',
                  'language',
                  'pushed_at',
                  'github_watchers',
                  'week_issue_change',
                ],
                Name: 'Standard Layout',
                AutoSizeColumns: true,
              },
            ],
          },
        }
      : // Bob
        {
          StatusBar: {
            StatusBars: [
              {
                Key: 'Center Panel',
                StatusBarPanels: ['FormatColumn', 'TeamSharing'],
              },
            ],
          },
          Layout: {
            CurrentLayout: 'Standard Layout',
            Layouts: [
              {
                TableColumns: [
                  'name',
                  'language',
                  'updated_at',
                  'pushed_at',
                  'github_watchers',
                  'week_issue_change',
                  'github_stars',
                  'license',
                  'has_projects',
                  'has_pages',
                  'created_at',
                  'has_wiki',
                ],
                Name: 'Standard Layout',
                AutoSizeColumns: true,
              },
            ],
          },
        };

  return {
    primaryKey: 'id',
    adaptableId: 'Referenced Objects Team Sharing',
    adaptableStateKey: `ReferencedObjectsTeamSharing_${userName}`,
    userName,
    initialState: {
      ...commonInitialState,
      ...userSpecificInitialState,
    },
    teamSharingOptions: {
      enableTeamSharing: true,
      loadSharedEntities: async () => {
        const data = localStorage.getItem(TEAM_SHARING_STATE_KEY);
        if (!data) {
          return [];
        }

        try {
          return JSON.parse(data);
        } catch (e) {
          return [];
        }
      },
      persistSharedEntities: entries => {
        localStorage.setItem(TEAM_SHARING_STATE_KEY, JSON.stringify(entries));
        return Promise.resolve();
      },
    },
    dashboardOptions: {
      customToolbars: [
        {
          name: 'CurrentUser',
          title: 'Current User',
          toolbarButtons: [
            {
              label: 'Alice',
              buttonStyle: () => {
                return {
                  tone: userName === 'Alice' ? 'success' : 'neutral',
                  variant: userName === 'Alice' ? 'raised' : 'outlined',
                };
              },
              onClick: () => {
                updateCurrentUser('Alice');
              },
            },
            {
              label: 'Bob',
              buttonStyle: () => {
                return {
                  tone: userName === 'Bob' ? 'success' : 'neutral',
                  variant: userName === 'Bob' ? 'raised' : 'outlined',
                };
              },
              onClick: () => {
                updateCurrentUser('Bob');
              },
            },
          ],
        },
      ],
      customDashboardButtons: [
        {
          tooltip: 'Reset state',
          icon: {
            name: 'refresh',
          },
          buttonStyle: {
            tone: 'error',
          },
          onClick: (button, context) => {
            localStorage.removeItem(TEAM_SHARING_STATE_KEY);
            ['Alice', 'Bob'].forEach(user => {
              localStorage.removeItem(`ReferencedObjectsTeamSharing_${user}`);
            });
            context.adaptableApi.stateApi.reloadInitialState();
          },
        },
      ],
    },
  };
};
```

**`src/index.ts`**

```ts
import {
  Adaptable,
  AdaptableApi,
  AdaptableOptions,
  AdaptableReadyInfo,
} from '@adaptabletools/adaptable';

import '@adaptabletools/adaptable/index.css';

import './styles.css';

import {gridOptions} from './gridOptions';
import {onAdaptableReady} from './onAdaptableReady';
import {agGridModules} from './agGridModules';
import {getAdaptableOptionsForUser} from './adaptableOptions';
import {WebFramework} from './rowData';

let currentAdaptableInstance: AdaptableApi | undefined;

let currentUser: 'Alice' | 'Bob' = 'Alice';

function updateCurrentUser(userName: 'Alice' | 'Bob') {
  currentUser = userName;
  initializeAdaptable(currentUser);
}

async function initializeAdaptable(userName: 'Alice' | 'Bob') {
  // destroy the previous instance (if existing)
  if (currentAdaptableInstance) {
    const config: any = {
      unmount: true,
      destroyApi: true,
    };
    currentAdaptableInstance.destroy(config);
  }

  currentAdaptableInstance = await Adaptable.init(
    {
      ...getAdaptableOptionsForUser(userName, updateCurrentUser),
    } as AdaptableOptions<WebFramework>,
    {gridOptions: {...gridOptions}, modules: agGridModules}
  );
  currentAdaptableInstance.eventApi.on(
    'AdaptableReady',
    (readyInfo: AdaptableReadyInfo) => {
      onAdaptableReady(readyInfo);
    }
  );
}

initializeAdaptable(currentUser);
```

**`src/App.tsx`** (React version)

```ts
import * as React from 'react';
import {useState} from 'react';
import {
  Adaptable,
  AdaptableApi,
  AdaptableReadyInfo,
} from '@adaptabletools/adaptable-react-aggrid';

// import adaptable css
import '@adaptabletools/adaptable-react-aggrid/index.css';
// import aggrid themes (using Balham theme)

import './styles.css';

import {onAdaptableReady} from './onAdaptableReady';
import {gridOptions} from './gridOptions';
import {agGridModules} from './agGridModules';
import {getAdaptableOptionsForUser} from './adaptableOptions';

const Grid = ({
  currentUser,
  onCurrentUserChange,
}: {
  currentUser: 'Alice' | 'Bob';
  onCurrentUserChange: (userName: 'Alice' | 'Bob') => void;
}) => {
  const adaptableApiRef = React.useRef<AdaptableApi>(null);

  const adaptableOptions = getAdaptableOptionsForUser(
    currentUser,
    onCurrentUserChange
  );

  const agGridOptions = {...gridOptions};
  return (
    <div style={{display: 'flex', flexFlow: 'column', height: '100vh'}}>
      <Adaptable.Provider
        gridOptions={agGridOptions}
        adaptableOptions={adaptableOptions}
        modules={[...agGridModules]}
        onAdaptableReady={(adaptableReadyInfo: AdaptableReadyInfo) => {
          // save a reference to adaptable api
          adaptableApiRef.current = adaptableReadyInfo.adaptableApi;
          onAdaptableReady(adaptableReadyInfo);
        }}>
        <Adaptable.UI key={`${currentUser}-ui`} style={{flex: 'none'}} />
        <Adaptable.AgGridReact />
      </Adaptable.Provider>
    </div>
  );
};

const App: React.FunctionComponent = () => {
  const [currentUser, setCurrentUser] = useState<'Alice' | 'Bob'>('Alice');

  return (
    <Grid
      key={currentUser}
      currentUser={currentUser}
      onCurrentUserChange={userName => setCurrentUser(userName)}
    />
  );
};
export default App;
```

**`src/app/app.component.ts`** (Angular version)

```ts
import {ChangeDetectorRef, Component, Inject} from '@angular/core';

import {AdaptableReadyInfo, AdaptableOptions} from '@adaptabletools/adaptable-angular-aggrid';
import {GridOptions} from 'ag-grid-enterprise';

// Adaptable styles
import '@adaptabletools/adaptable-angular-aggrid/index.css';

// AG Grid styles

import './styles.css';

// grid configuration
import {gridOptions} from './gridOptions';
import {agGridModules} from './agGridModules';
import {onAdaptableReady} from './onAdaptableReady';
import {getAdaptableOptionsForUser} from './adaptableOptions';
import {WebFramework} from './rowData';

@Component({
  standalone: false,
  selector: 'app-root',
  template: `
    <div id="demoOutputAbove"></div>
    <adaptable-provider
      *ngIf="isUpToDate"
      [adaptableOptions]="adaptableOpts"
      [gridOptions]="agGridOptions"
      [modules]="modules"
      (adaptableReady)="adaptableReady($event)"
      style="height: 100vh; width: 100vw;">
      <adaptable-ui style="flex: none"></adaptable-ui>
      <ag-grid-angular
        *adaptable="let adaptable"
        [gridOptions]="adaptable.gridOptions"
        [modules]="adaptable.modules"
        style="flex: 1">
      </ag-grid-angular>
    </adaptable-provider>
    <div id="demoOutputBelow"></div>
  `,
  styles: [
    `
      :host {
        height: 100vh;
        display: flex;
        flex-flow: column;
      }
    `,
  ],
})
export class AppComponent {
  adaptableOpts: AdaptableOptions<WebFramework>;
  agGridOptions: GridOptions<WebFramework>;
  modules = agGridModules;

  currentUser: 'Alice' | 'Bob';
  isUpToDate = true;

  constructor(
    @Inject(ChangeDetectorRef) private changeDetectorRef: ChangeDetectorRef
  ) {
    this.currentUser = 'Alice';
    this.adaptableOpts = getAdaptableOptionsForUser(
      this.currentUser,
      (user: 'Alice' | 'Bob') => this.setCurrentUser(user)
    );
    this.agGridOptions = {...gridOptions};
  }

  setCurrentUser(currentUser: 'Alice' | 'Bob') {
    this.isUpToDate = false;
    this.changeDetectorRef.detectChanges();

    this.currentUser = currentUser;
    this.initializeAdaptable();
    this.isUpToDate = true;
    this.changeDetectorRef.detectChanges();
  }

  initializeAdaptable() {
    this.adaptableOpts = getAdaptableOptionsForUser(
      this.currentUser,
      (user: 'Alice' | 'Bob') => this.setCurrentUser(user)
    );
    this.agGridOptions = {...gridOptions};
  }

  adaptableReady($event: AdaptableReadyInfo) {
    onAdaptableReady($event);
  }
}
```

**`src/App.vue`** (Vue version)

```ts
<template>
  <Grid
    :key="currentUser"
    :currentUser="currentUser"
    @currentUserChange="setCurrentUser" />
</template>

<script lang="ts">
import {ref, defineComponent} from 'vue';
import {
  AdaptableProvider,
  AdaptableAgGridVue,
  AdaptableUI,
} from '@adaptabletools/adaptable-vue3-aggrid';

import {onAdaptableReady} from './onAdaptableReady';
import {gridOptions} from './gridOptions';
import {agGridModules} from './agGridModules';
import {getAdaptableOptionsForUser} from './adaptableOptions';

const Grid = defineComponent({
  props: {
    currentUser: {
      type: String,
      required: true,
    },
  },
  emits: ['currentUserChange'],
  setup(props, {emit}) {
    const adaptableOptions = getAdaptableOptionsForUser(
      props.currentUser,
      userName => emit('currentUserChange', userName)
    );

    const agGridOptions = {...gridOptions};

    return {
      adaptableOptions,
      agGridOptions,
      agGridModules,
      onAdaptableReady,
    };
  },
  components: {
    AdaptableProvider,
    AdaptableAgGridVue,
    AdaptableUI,
  },
  template: `
    <AdaptableProvider
        :gridOptions="agGridOptions"
        :adaptableOptions="adaptableOptions"
        :modules="agGridModules"
        @onAdaptableReady="onAdaptableReady">
      <div style="display: flex; flex-direction: column; height: 100vh">
        <AdaptableUI :key="currentUser + '-ui'" style="flex: none" />
        <AdaptableAgGridVue style="flex: 1"  />
      </div>
    </AdaptableProvider>
  `,
});

export default defineComponent({
  name: 'App',
  components: {
    Grid,
  },
  setup() {
    const currentUser = ref('Alice');

    const setCurrentUser = userName => {
      currentUser.value = userName;
    };

    return {
      currentUser,
      setCurrentUser,
    };
  },
});
</script>
```

**`src/onAdaptableReady.ts`**

```ts
import {AdaptableReadyInfo} from '@adaptabletools/adaptable';

export const onAdaptableReady = ({adaptableApi}: AdaptableReadyInfo) => {
  // trigger loading shared entries to be able to show/hide the import button for user 'Bob'
  // by default the shared-entries are loaded only when the team sharing popup is opened.
  adaptableApi.teamSharingApi.refreshTeamSharing();
};
```

## Sharing Layouts

Another common use case for Referenced Team Sharing is when a [Layout](https://www.adaptabletools.com/docs/handbook-layouts/index.md) is shared.

A Layout can include references to other objects in 2 ways:

- by containing **Special Columns** - e.g. Calculated Columns or FreeText Columns
- by being an **Extended Layout** which includes other objects (like Format or Styled Columns)

### Special Columns

Any [Layout](https://www.adaptabletools.com/docs/handbook-layouts/index.md) which contains references to [Calculated Columns](https://www.adaptabletools.com/docs/handbook-calculated-column/index.md) or [FreeText Columns](https://www.adaptabletools.com/docs/handbook-freetext-column/index.md) will automatically include them in Referenced Sharing.

**Example: Referenced Team Sharing: Layouts**

Team Sharing Layouts with Special Columns

- In this demo we provided **Alice** with a [Layout](https://www.adaptabletools.com/docs/handbook-layouts/index.md) entitled `Special Column View` which contains:
  - a [Calculated Column](https://www.adaptabletools.com/docs/handbook-calculated-column/index.md) called `Subscribers Ratio`
  - a [FreeText Column](https://www.adaptabletools.com/docs/handbook-freetext-column/index.md) called `Comments`
- We have also provided a [Custom Dashboard Button](https://www.adaptabletools.com/docs/ui-dashboard-buttons/index.md) for **Alice** to team-share the `Special Column View` Layout

- As **Alice** shares the Layout by clicking the 'Share Special Column View' button in the Dashboard
- Switch to **Bob** and open TeamShare
- Note that not only is the Layout there but so are the Calculated and FreeText Columns
- Select the 'Special Column View' Layout and see how the Shared Layout automatically includes the 2 Columns

Demo project (Vanilla); the files without a marker are shown below:

```text
src/
  adaptableOptions.ts
  agGridModules.ts     [template]
  columnDefs.ts        [template]
  gridOptions.ts       [template]
  index.ts
  onAdaptableReady.ts
  rowData.ts           [template]
  styles.css           [template]
index.html             [template]
package.json           [template]
tsconfig.json          [template]
```

Files marked `[template]` are the same in every demo; see the [demo template](https://www.adaptabletools.com/llms/demo-template.md#vanilla).

**`src/adaptableOptions.ts`**

```ts
import {
  AdaptableOptions,
  DashboardOptions,
  InitialState,
} from '@adaptabletools/adaptable';
import {WebFramework} from './rowData';

// use a common Team Sharing state key for both users
const TEAM_SHARING_STATE_KEY =
  'ReferencedSpecialColumnTeamSharing_TeamSharingState';

export const getAdaptableOptionsForUser = (
  userName: 'Alice' | 'Bob',
  updateCurrentUser: (userName: 'Alice' | 'Bob') => void
): AdaptableOptions => {
  const commonAdaptableOptions: AdaptableOptions<WebFramework> = {
    primaryKey: 'id',
    adaptableId: 'Referenced Special Columns Team Sharing',
    adaptableStateKey: `ReferencedSpecialColumnsTeamSharing_${userName}`,
    userName,
    teamSharingOptions: {
      enableTeamSharing: true,
      loadSharedEntities: async adaptableId => {
        const data = localStorage.getItem(TEAM_SHARING_STATE_KEY);
        if (!data) {
          return [];
        }

        try {
          return JSON.parse(data);
        } catch (e) {
          return [];
        }
      },
      persistSharedEntities: entries => {
        localStorage.setItem(TEAM_SHARING_STATE_KEY, JSON.stringify(entries));
        return Promise.resolve();
      },
    },
    initialState: {
      Layout: {
        CurrentLayout: 'Special Column View',
        Layouts: [
          {
            Name: 'Special Column View',
            TableColumns: [
              'name',
              'language',
              'github_stars',
              'github_watchers',
              'subscribersRatio',
              'comments',
              'open_pr_count',
              'closed_issues_count',
              'created_at',
              'updated_at',
              'pushed_at',
              'license',
              'created_at',
              'has_wiki',
            ],
            AutoSizeColumns: true,
          },
        ],
      },
    },
  };

  const changeUserState: InitialState['Dashboard'] = {
    Revision: Date.now(),
    Tabs: [
      {
        Name: 'Select Current User',
        Toolbars: ['CurrentUser', 'Layout'],
      },
    ],
    ModuleButtons: ['Layout', 'TeamSharing'],
  };

  const changeUserDashboardOptions: DashboardOptions = {
    customToolbars: [
      {
        name: 'CurrentUser',
        title: 'Current User',
        toolbarButtons: [
          {
            label: 'Alice',
            buttonStyle: () => {
              return {
                tone: userName === 'Alice' ? 'success' : 'neutral',
                variant: userName === 'Alice' ? 'raised' : 'outlined',
              };
            },
            onClick: () => {
              updateCurrentUser('Alice');
            },
          },
          {
            label: 'Bob',
            buttonStyle: () => {
              return {
                tone: userName === 'Bob' ? 'success' : 'neutral',
                variant: userName === 'Bob' ? 'raised' : 'outlined',
              };
            },
            onClick: () => {
              updateCurrentUser('Bob');
            },
          },
        ],
      },
    ],
  };

  const userSpecificAdaptableOptions: Partial<AdaptableOptions<WebFramework>> =
    userName === 'Alice'
      ? {
          dashboardOptions: {
            ...changeUserDashboardOptions,
            customDashboardButtons: [
              {
                label: 'Share Layout: "Special Column View" ',
                buttonStyle: {
                  tone: 'neutral',
                  variant: 'raised',
                },
                onClick: (button, {adaptableApi}) => {
                  const currentLayout =
                    adaptableApi.layoutApi.getCurrentLayout();
                  adaptableApi.teamSharingApi.shareAdaptableEntity(
                    currentLayout,
                    'Layout',
                    {
                      description: 'Share Layout Special Column View',
                      type: 'Snapshot',
                    }
                  );
                },
              },
              {
                tooltip: 'Reset state',
                icon: {
                  name: 'refresh',
                },
                buttonStyle: {
                  tone: 'error',
                },
                onClick: (button, context) => {
                  localStorage.removeItem(TEAM_SHARING_STATE_KEY);
                  ['Alice', 'Bob'].forEach(user => {
                    localStorage.removeItem(
                      `ReferencedSpecialColumnsTeamSharing_${user}`
                    );
                  });
                  context.adaptableApi.stateApi.reloadInitialState();
                },
              },
            ],
          },
          initialState: {
            Dashboard: changeUserState,
            StatusBar: {
              StatusBars: [
                {
                  Key: 'Center Panel',
                  StatusBarPanels: ['Layout', 'TeamSharing'],
                },
              ],
            },
            Layout: {
              CurrentLayout: 'Special Column View',
              Layouts: [
                {
                  Name: 'Special Column View',
                  TableColumns: [
                    'name',
                    'language',
                    'github_stars',
                    'github_watchers',
                    'subscribersRatio',
                    'comments',
                    'open_pr_count',
                    'closed_issues_count',
                    'created_at',
                    'updated_at',
                    'pushed_at',
                    'license',
                    'created_at',
                    'has_wiki',
                  ],
                  AutoSizeColumns: true,
                },
              ],
            },
            CalculatedColumn: {
              CalculatedColumns: [
                {
                  FriendlyName: 'Subscribers Ratio',
                  ColumnId: 'subscribersRatio',
                  Expression: '[github_stars] / [github_watchers]',
                  CalculatedColumnSettings: {
                    DataType: 'number',
                  },
                },
              ],
            },
            FreeTextColumn: {
              FreeTextColumns: [
                {
                  ColumnId: 'comments',
                  FriendlyName: 'Comments',
                  FreeTextColumnSettings: {
                    DataType: 'text',
                  },
                  FreeTextStoredValues: [
                    {PrimaryKey: 24195339, FreeText: 'Used by the US team'},
                  ],
                },
              ],
            },
          },
        }
      : // Bob
        {
          dashboardOptions: {
            ...changeUserDashboardOptions,
            customDashboardButtons: [
              {
                label: 'Import Layout',
                buttonStyle: {
                  tone: 'neutral',
                  variant: 'raised',
                },
                hidden: (button, {adaptableApi}) => {
                  const sharedEntries =
                    adaptableApi.teamSharingApi.getLoadedAdaptableSharedEntities();

                  // show if there is a layout object shared
                  if (sharedEntries?.length) {
                    return !sharedEntries.some(
                      sharedEntry => sharedEntry.Module === 'Layout'
                    );
                  }

                  return true;
                },
                onClick: async (button, {adaptableApi}) => {
                  await adaptableApi.teamSharingApi.loadSharedEntities();
                  const sharedObjects =
                    adaptableApi.teamSharingApi.getLoadedAdaptableSharedEntities();

                  const layout = sharedObjects.find(
                    sharedObject => sharedObject.Module === 'Layout'
                  );
                  if (!layout) {
                    return;
                  }

                  adaptableApi.teamSharingApi.importSharedEntry(layout);
                },
              },
              {
                tooltip: 'Reset state',
                icon: {
                  name: 'refresh',
                },
                buttonStyle: {
                  tone: 'error',
                },
                onClick: (button, context) => {
                  localStorage.removeItem(TEAM_SHARING_STATE_KEY);
                  ['Alice', 'Bob'].forEach(user => {
                    localStorage.removeItem(
                      `ReferencedSpecialColumnsTeamSharing_${user}`
                    );
                  });
                  context.adaptableApi.stateApi.reloadInitialState();
                },
              },
            ],
          },
          initialState: {
            Dashboard: changeUserState,
            StatusBar: {
              StatusBars: [
                {
                  Key: 'Center Panel',
                  StatusBarPanels: ['Layout', 'TeamSharing'],
                },
              ],
            },
            Layout: {
              CurrentLayout: 'Default',
              Layouts: [
                {
                  Name: 'Default',
                  TableColumns: [
                    'name',
                    'language',
                    'github_stars',
                    'github_watchers',
                    'open_pr_count',
                    'closed_issues_count',
                    'created_at',
                    'updated_at',
                    'pushed_at',
                    'license',
                    'created_at',
                    'has_wiki',
                  ],
                  AutoSizeColumns: true,
                },
              ],
            },
          },
        };

  return {
    ...commonAdaptableOptions,
    ...userSpecificAdaptableOptions,
  };
};
```

**`src/index.ts`**

```ts
import {
  Adaptable,
  AdaptableApi,
  AdaptableOptions,
  AdaptableReadyInfo,
} from '@adaptabletools/adaptable';

import '@adaptabletools/adaptable/index.css';

import './styles.css';

import {gridOptions} from './gridOptions';
import {onAdaptableReady} from './onAdaptableReady';
import {agGridModules} from './agGridModules';
import {getAdaptableOptionsForUser} from './adaptableOptions';
import {WebFramework} from './rowData';

let currentAdaptableInstance: AdaptableApi | undefined;

let currentUser: 'Alice' | 'Bob' = 'Alice';

function updateCurrentUser(userName: 'Alice' | 'Bob') {
  currentUser = userName;
  initializeAdaptable(currentUser);
}

async function initializeAdaptable(userName: 'Alice' | 'Bob') {
  // destroy the previous instance (if existing)
  if (currentAdaptableInstance) {
    const config: any = {
      unmount: true,
      destroyApi: true,
    };
    currentAdaptableInstance.destroy(config);
  }

  currentAdaptableInstance = await Adaptable.init(
    {
      ...getAdaptableOptionsForUser(userName, updateCurrentUser),
    } as AdaptableOptions<WebFramework>,
    {gridOptions: {...gridOptions}, modules: agGridModules}
  );
  currentAdaptableInstance.eventApi.on(
    'AdaptableReady',
    (readyInfo: AdaptableReadyInfo) => {
      onAdaptableReady(readyInfo);
    }
  );
}

initializeAdaptable(currentUser);
```

**`src/App.tsx`** (React version)

```ts
import * as React from 'react';
import {useState} from 'react';
import {
  Adaptable,
  AdaptableApi,
  AdaptableReadyInfo,
} from '@adaptabletools/adaptable-react-aggrid';

// import adaptable css
import '@adaptabletools/adaptable-react-aggrid/index.css';
// import aggrid themes (using Balham theme)

import './styles.css';

import {onAdaptableReady} from './onAdaptableReady';
import {gridOptions} from './gridOptions';
import {agGridModules} from './agGridModules';
import {getAdaptableOptionsForUser} from './adaptableOptions';

const Grid = ({
  currentUser,
  onCurrentUserChange,
}: {
  currentUser: 'Alice' | 'Bob';
  onCurrentUserChange: (userName: 'Alice' | 'Bob') => void;
}) => {
  const adaptableApiRef = React.useRef<AdaptableApi>(null);

  const adaptableOptions = getAdaptableOptionsForUser(
    currentUser,
    onCurrentUserChange
  );

  const agGridOptions = {...gridOptions};
  return (
    <div style={{display: 'flex', flexFlow: 'column', height: '100vh'}}>
      <Adaptable.Provider
        gridOptions={agGridOptions}
        adaptableOptions={adaptableOptions}
        modules={[...agGridModules]}
        onAdaptableReady={(adaptableReadyInfo: AdaptableReadyInfo) => {
          // save a reference to adaptable api
          adaptableApiRef.current = adaptableReadyInfo.adaptableApi;
          onAdaptableReady(adaptableReadyInfo);
        }}>
        <Adaptable.UI key={`${currentUser}-ui`} style={{flex: 'none'}} />
        <Adaptable.AgGridReact />
      </Adaptable.Provider>
    </div>
  );
};

const App: React.FunctionComponent = () => {
  const [currentUser, setCurrentUser] = useState<'Alice' | 'Bob'>('Alice');

  return (
    <Grid
      key={currentUser}
      currentUser={currentUser}
      onCurrentUserChange={userName => setCurrentUser(userName)}
    />
  );
};
export default App;
```

**`src/app/app.component.ts`** (Angular version)

```ts
import {ChangeDetectorRef, Component, Inject} from '@angular/core';

import {AdaptableReadyInfo, AdaptableOptions} from '@adaptabletools/adaptable-angular-aggrid';
import {GridOptions} from 'ag-grid-enterprise';

// Adaptable styles
import '@adaptabletools/adaptable-angular-aggrid/index.css';

// AG Grid styles

import './styles.css';

// grid configuration
import {gridOptions} from './gridOptions';
import {agGridModules} from './agGridModules';
import {onAdaptableReady} from './onAdaptableReady';
import {getAdaptableOptionsForUser} from './adaptableOptions';
import {WebFramework} from './rowData';

@Component({
  standalone: false,
  selector: 'app-root',
  template: `
    <div id="demoOutputAbove"></div>
    <adaptable-provider
      *ngIf="isUpToDate"
      [adaptableOptions]="adaptableOpts"
      [gridOptions]="agGridOptions"
      [modules]="modules"
      (adaptableReady)="adaptableReady($event)"
      style="height: 100vh; width: 100vw;">
      <adaptable-ui style="flex: none"></adaptable-ui>
      <ag-grid-angular
        *adaptable="let adaptable"
        [gridOptions]="adaptable.gridOptions"
        [modules]="adaptable.modules"
        style="flex: 1">
      </ag-grid-angular>
    </adaptable-provider>
    <div id="demoOutputBelow"></div>
  `,
  styles: [
    `
      :host {
        height: 100vh;
        display: flex;
        flex-flow: column;
      }
    `,
  ],
})
export class AppComponent {
  adaptableOpts: AdaptableOptions<WebFramework>;
  agGridOptions: GridOptions<WebFramework>;
  modules = agGridModules;

  currentUser: 'Alice' | 'Bob';
  isUpToDate = true;

  constructor(
    @Inject(ChangeDetectorRef) private changeDetectorRef: ChangeDetectorRef
  ) {
    this.currentUser = 'Alice';
    this.adaptableOpts = getAdaptableOptionsForUser(
      this.currentUser,
      (user: 'Alice' | 'Bob') => this.setCurrentUser(user)
    );
    this.agGridOptions = {...gridOptions};
  }

  setCurrentUser(currentUser: 'Alice' | 'Bob') {
    this.isUpToDate = false;
    this.changeDetectorRef.detectChanges();

    this.currentUser = currentUser;
    this.initializeAdaptable();
    this.isUpToDate = true;
    this.changeDetectorRef.detectChanges();
  }

  initializeAdaptable() {
    this.adaptableOpts = getAdaptableOptionsForUser(
      this.currentUser,
      (user: 'Alice' | 'Bob') => this.setCurrentUser(user)
    );
    this.agGridOptions = {...gridOptions};
  }

  adaptableReady($event: AdaptableReadyInfo) {
    onAdaptableReady($event);
  }
}
```

**`src/App.vue`** (Vue version)

```ts
<template>
  <Grid
    :key="currentUser"
    :currentUser="currentUser"
    @currentUserChange="setCurrentUser" />
</template>

<script lang="ts">
import {ref, defineComponent} from 'vue';
import {
  AdaptableProvider,
  AdaptableAgGridVue,
  AdaptableUI,
} from '@adaptabletools/adaptable-vue3-aggrid';

import {onAdaptableReady} from './onAdaptableReady';
import {gridOptions} from './gridOptions';
import {agGridModules} from './agGridModules';
import {getAdaptableOptionsForUser} from './adaptableOptions';

const Grid = defineComponent({
  props: {
    currentUser: {
      type: String,
      required: true,
    },
  },
  emits: ['currentUserChange'],
  setup(props, {emit}) {
    const adaptableOptions = getAdaptableOptionsForUser(
      props.currentUser,
      userName => emit('currentUserChange', userName)
    );

    const agGridOptions = {...gridOptions};

    return {
      adaptableOptions,
      agGridOptions,
      agGridModules,
      onAdaptableReady,
    };
  },
  components: {
    AdaptableProvider,
    AdaptableAgGridVue,
    AdaptableUI,
  },
  template: `
    <AdaptableProvider
        :gridOptions="agGridOptions"
        :adaptableOptions="adaptableOptions"
        :modules="agGridModules"
        @onAdaptableReady="onAdaptableReady">
      <div style="display: flex; flex-direction: column; height: 100vh">
        <AdaptableUI :key="currentUser + '-ui'" style="flex: none" />
        <AdaptableAgGridVue style="flex: 1"  />
      </div>
    </AdaptableProvider>
  `,
});

export default defineComponent({
  name: 'App',
  components: {
    Grid,
  },
  setup() {
    const currentUser = ref('Alice');

    const setCurrentUser = userName => {
      currentUser.value = userName;
    };

    return {
      currentUser,
      setCurrentUser,
    };
  },
});
</script>
```

**`src/onAdaptableReady.ts`**

```ts
import {AdaptableReadyInfo} from '@adaptabletools/adaptable';

export const onAdaptableReady = ({adaptableApi}: AdaptableReadyInfo) => {
  // trigger loading shared entries to be able to show/hide the import button for UserB
  // by default the shared-entries are loaded only when the team sharing popup is opened.
  adaptableApi.teamSharingApi.refreshTeamSharing();
};
```

### Extended Layouts

Referenced Sharing will also take into consideration any [Extended Layouts](https://www.adaptabletools.com/docs/handbook-layouts-extending/index.md).

If objects (e.g. Format Columns) have been extended into a Layout, they will be included in the Referenced Share.

The Shared Entity stores **`LayoutExtensions`** — which objects were extended into the Layout at share time — so import recreates the same Extended Layout on the downloader's grid.

- Only objects explicitly extended into the Layout are shared — global objects (available in every Layout) are not included
- If an Active Share is used, changing which objects are extended into the Layout will update the Share
- Shared entities are migrated on load when [autoMigrateState](https://www.adaptabletools.com/docs/dev-guide-adaptable-state-migrating-state/index.md) is enabled; see [Migrating Shared Entities](https://www.adaptabletools.com/docs/handbook-team-sharing-configuring/index.md#migrating-shared-entities) and the [Version 24 Release Note](https://www.adaptabletools.com/support/version-240-release-note) when planning a shared-store upgrade.

See [Extending Layouts](https://www.adaptabletools.com/docs/handbook-layouts/index.md#extending-layouts) for detailed instructions on how to scope [Adaptable Objects](https://www.adaptabletools.com/docs/dev-guide-adaptable-state-initial-state/index.md#adaptable-objects) to particular Layouts

**Example: Referenced Team Sharing: Extended Layouts**

Team Sharing Extended Layouts

- This demo illustrates Referenced Sharing of Extended Layouts
- **Alice** has 2 Layouts - each with a different set of [Format Columns](https://www.adaptabletools.com/docs/handbook-column-formatting/index.md) and [Styled Columns](https://www.adaptabletools.com/docs/handbook-styled-column-overview/index.md) extended into that Layout:
  - `First View` - `Name`, `Language` and `Date` columns
  - `Second View` - `Github Stars`, `Closed Issues` and also `Date` columns, plus a [Condition](https://www.adaptabletools.com/docs/handbook-column-formatting-conditions/index.md) where Language is 'HTML'
- There is a button in the Dashboard for **Alice** to share the `First View` Layout

- As **Alice** shares the `First View` Layout by clicking the 'Share Layout: First View' button in the Dashboard
- Switch to **Bob** and open TeamShare
- You will note that not only is the Layout there but so are the associated Format Columns
- Upload the `First View` Layout and you will see that the Shared Layout automatically includes all the extended Objects

Demo project (Vanilla); the files without a marker are shown below:

```text
src/
  adaptableOptions.ts
  agGridModules.ts     [template]
  columnDefs.ts        [template]
  gridOptions.ts       [template]
  index.ts
  onAdaptableReady.ts  [template]
  rowData.ts           [template]
  styles.css           [template]
index.html             [template]
package.json           [template]
tsconfig.json          [template]
```

Files marked `[template]` are the same in every demo; see the [demo template](https://www.adaptabletools.com/llms/demo-template.md#vanilla).

**`src/adaptableOptions.ts`**

```ts
import {
  AdaptableOptions,
  DashboardOptions,
  InitialState,
} from '@adaptabletools/adaptable';
import {WebFramework} from './rowData';

// use a common Team Sharing state key for both users
const TEAM_SHARING_STATE_KEY = 'ExtendedLayoutTeamSharing_TeamSharingState';

export const getAdaptableOptionsForUser = (
  userName: 'Alice' | 'Bob',
  updateCurrentUser: (userName: 'Alice' | 'Bob') => void
): AdaptableOptions<WebFramework> => {
  const commonAdaptableOptions: AdaptableOptions<WebFramework> = {
    primaryKey: 'id',
    adaptableId: 'Extended Layout Team Sharing',
    adaptableStateKey: `ExtendedLayoutTeamSharing_${userName}`,
    userName,
    layoutOptions: {
      enableLayoutExtensionsUI: true,
    },
    teamSharingOptions: {
      enableTeamSharing: true,
      loadSharedEntities: async adaptableId => {
        const data = localStorage.getItem(TEAM_SHARING_STATE_KEY);
        if (!data) {
          return [];
        }

        try {
          return JSON.parse(data);
        } catch (e) {
          return [];
        }
      },
      persistSharedEntities: entries => {
        localStorage.setItem(TEAM_SHARING_STATE_KEY, JSON.stringify(entries));
        return Promise.resolve();
      },
    },
    initialState: {
      Layout: {
        CurrentLayout: 'First View',
        Layouts: [
          {
            Name: 'First View',
            TableColumns: [
              'name',
              'language',
              'github_stars',
              'open_pr_count',
              'closed_issues_count',
              'created_at',
              'updated_at',
              'pushed_at',
              'license',
              'created_at',
              'has_wiki',
              'github_watchers',
              'description',
              'open_issues_count',
              'closed_pr_count',
              'has_projects',
              'has_pages',
              'week_issue_change',
            ],
            AutoSizeColumns: true,
          },
        ],
      },
    },
  };

  const changeUserState: InitialState['Dashboard'] = {
    Revision: Date.now(),
    Tabs: [
      {
        Name: 'Select Current User',
        Toolbars: ['CurrentUser', 'Layout'],
      },
    ],
    ModuleButtons: ['Layout', 'TeamSharing'],
  };

  const changeUserDashboardOptions: DashboardOptions = {
    customToolbars: [
      {
        name: 'CurrentUser',
        title: 'Current User',
        toolbarButtons: [
          {
            label: 'Alice',
            buttonStyle: () => {
              return {
                tone: userName === 'Alice' ? 'success' : 'neutral',
                variant: userName === 'Alice' ? 'raised' : 'outlined',
              };
            },
            onClick: () => {
              updateCurrentUser('Alice');
            },
          },
          {
            label: 'Bob',
            buttonStyle: () => {
              return {
                tone: userName === 'Bob' ? 'success' : 'neutral',
                variant: userName === 'Bob' ? 'raised' : 'outlined',
              };
            },
            onClick: () => {
              updateCurrentUser('Bob');
            },
          },
        ],
      },
    ],
  };

  const userSpecificAdaptableOptions: Partial<AdaptableOptions<WebFramework>> =
    userName === 'Alice'
      ? {
          dashboardOptions: {
            ...changeUserDashboardOptions,
            customDashboardButtons: [
              {
                label: 'Share Layout: "First View" ',
                buttonStyle: {
                  tone: 'neutral',
                  variant: 'raised',
                },
                onClick: (button, {adaptableApi}) => {
                  const currentLayout =
                    adaptableApi.layoutApi.getCurrentLayout();
                  adaptableApi.teamSharingApi.shareAdaptableEntity(
                    currentLayout,
                    'Layout',
                    {
                      description: 'Share Layout First View',
                      type: 'Snapshot',
                    }
                  );
                },
              },
              {
                tooltip: 'Reset state',
                icon: {
                  name: 'refresh',
                },
                buttonStyle: {
                  tone: 'error',
                },
                onClick: (button, context) => {
                  localStorage.removeItem(TEAM_SHARING_STATE_KEY);
                  ['Alice', 'Bob'].forEach(user => {
                    localStorage.removeItem(
                      `ExtendedLayoutTeamSharing_${user}`
                    );
                  });
                  context.adaptableApi.stateApi.reloadInitialState();
                },
              },
            ],
          },
          initialState: {
            Dashboard: changeUserState,
            StatusBar: {
              StatusBars: [
                {
                  Key: 'Center Panel',
                  StatusBarPanels: ['Layout', 'TeamSharing'],
                },
              ],
            },
            Layout: {
              CurrentLayout: 'First View',
              Layouts: [
                {
                  Name: 'First View',
                  TableColumns: [
                    'name',
                    'language',
                    'github_stars',
                    'open_pr_count',
                    'closed_issues_count',
                    'created_at',
                    'updated_at',
                    'pushed_at',
                    'license',
                    'created_at',
                    'has_wiki',
                    'github_watchers',
                    'description',
                    'open_issues_count',
                    'closed_pr_count',
                    'has_projects',
                    'has_pages',
                    'week_issue_change',
                  ],
                  AutoSizeColumns: true,
                },
                {
                  Name: 'Second View',
                  TableColumns: [
                    'name',
                    'github_stars',
                    'closed_issues_count',
                    'language',
                    'created_at',
                    'updated_at',
                    'pushed_at',
                  ],
                  AutoSizeColumns: true,
                },
              ],
              LayoutExtensions: [
                {
                  LayoutName: 'First View',
                  FormatColumn: [
                    'formatColumn-name',
                    'formatColumn-date',
                    'formatColumn-language',
                  ],
                  StyledColumn: ['open_pr_count Gradient'],
                },
                {
                  LayoutName: 'Second View',
                  FormatColumn: [
                    'formatColumn-github_stars',
                    'formatColumn-date',
                    'formatColumn-all',
                  ],
                  StyledColumn: ['closed_issues_count Percent Bar'],
                },
              ],
            },
            FormatColumn: {
              FormatColumns: [
                {
                  Name: 'formatColumn-name',
                  Scope: {
                    ColumnIds: ['name'],
                  },
                  Style: {
                    FontWeight: 'Bold',
                  },
                },

                {
                  Name: 'formatColumn-github_stars',
                  Scope: {
                    ColumnIds: ['github_stars'],
                  },
                  Style: {
                    ForeColor: '#c2bb00',
                    BackColor: '#f5f5f5',
                  },
                  DisplayFormat: {
                    Formatter: 'NumberFormatter',
                    Options: {
                      Prefix: 'Stars: ',
                    },
                  },
                },

                {
                  Name: 'formatColumn-date',
                  Scope: {
                    DataTypes: ['date'],
                  },
                  Style: {
                    FontStyle: 'Italic',
                    Alignment: 'Center',
                  },
                  DisplayFormat: {
                    Formatter: 'DateFormatter',
                    Options: {
                      Pattern: 'MMM do yyyy',
                    },
                  },
                },
                {
                  Name: 'formatColumn-language',
                  Style: {
                    BackColor: 'var(--ab-color-palette-25)',
                  },
                  Scope: {
                    ColumnIds: ['language'],
                  },
                  Rule: '[language] = "TypeScript"',
                },
                {
                  Name: 'formatColumn-all',
                  Style: {
                    BackColor: 'var(--ab-color-palette-32)',
                  },
                  Scope: {
                    All: true,
                  },
                  Rule: '[language] = "HTML"',
                },
              ],
            },
            StyledColumn: {
              StyledColumns: [
                {
                  ColumnId: 'open_pr_count',
                  Name: 'open_pr_count Gradient',
                  GradientStyle: {
                    CellRanges: [
                      {
                        Min: 0,
                        Max: 254,
                        Color: '#a52a2a',
                      },
                    ],
                  },
                },
                {
                  ColumnId: 'closed_issues_count',
                  Name: 'closed_issues_count Percent Bar',
                  PercentBarStyle: {
                    RangeValueType: 'Number',
                    CellRanges: [
                      {
                        Min: 0,
                        Max: 21706,
                        Color: 'purple',
                      },
                    ],
                    CellTextProperties: {
                      CellTextLayout: {
                        PercentValue: { Horizontal: 'Left', Vertical: 'Below' },
                      },
                    },
                  },
                },
              ],
            },
          },
        }
      : // Bob
        {
          dashboardOptions: {
            ...changeUserDashboardOptions,
            customDashboardButtons: [
              {
                label: 'Import Layout',
                buttonStyle: {
                  tone: 'neutral',
                  variant: 'raised',
                },
                hidden: (button, {adaptableApi}) => {
                  const sharedEntries =
                    adaptableApi.teamSharingApi.getLoadedAdaptableSharedEntities();

                  // show if there is a layout object shared
                  if (sharedEntries?.length) {
                    return !sharedEntries.some(
                      sharedEntry => sharedEntry.Module === 'Layout'
                    );
                  }

                  return true;
                },
                onClick: async (button, {adaptableApi}) => {
                  await adaptableApi.teamSharingApi.loadSharedEntities();
                  const sharedObjects =
                    adaptableApi.teamSharingApi.getLoadedAdaptableSharedEntities();

                  const layout = sharedObjects.find(
                    sharedObject => sharedObject.Module === 'Layout'
                  );
                  if (!layout) {
                    return;
                  }

                  adaptableApi.teamSharingApi.importSharedEntry(layout);
                },
              },
              {
                tooltip: 'Reset state',
                icon: {
                  name: 'refresh',
                },
                buttonStyle: {
                  tone: 'error',
                },
                onClick: (button, context) => {
                  localStorage.removeItem(TEAM_SHARING_STATE_KEY);
                  ['Alice', 'Bob'].forEach(user => {
                    localStorage.removeItem(
                      `ExtendedLayoutTeamSharing_${user}`
                    );
                  });
                  context.adaptableApi.stateApi.reloadInitialState();
                },
              },
            ],
          },
          initialState: {
            Dashboard: changeUserState,
            StatusBar: {
              StatusBars: [
                {
                  Key: 'Center Panel',
                  StatusBarPanels: ['Layout', 'TeamSharing'],
                },
              ],
            },
            Layout: {
              CurrentLayout: 'First View',
              Layouts: [
                {
                  Name: 'First View',
                  TableColumns: [
                    'name',
                    'language',
                    'github_stars',
                    'open_pr_count',
                    'closed_issues_count',
                    'created_at',
                    'updated_at',
                    'pushed_at',
                    'license',
                    'created_at',
                    'has_wiki',
                    'github_watchers',
                    'description',
                    'open_issues_count',
                    'closed_pr_count',
                    'has_projects',
                    'has_pages',
                    'week_issue_change',
                  ],
                  AutoSizeColumns: true,
                },
              ],
            },
          },
        };

  return {
    ...commonAdaptableOptions,
    ...userSpecificAdaptableOptions,
  };
};
```

**`src/index.ts`**

```ts
import {
  Adaptable,
  AdaptableApi,
  AdaptableOptions,
  AdaptableReadyInfo,
} from '@adaptabletools/adaptable';

import '@adaptabletools/adaptable/index.css';

import './styles.css';

import {gridOptions} from './gridOptions';
import {onAdaptableReady} from './onAdaptableReady';
import {agGridModules} from './agGridModules';
import {getAdaptableOptionsForUser} from './adaptableOptions';
import {WebFramework} from './rowData';

let currentAdaptableInstance: AdaptableApi | undefined;

let currentUser: 'Alice' | 'Bob' = 'Alice';

function updateCurrentUser(userName: 'Alice' | 'Bob') {
  currentUser = userName;
  initializeAdaptable(currentUser);
}

async function initializeAdaptable(userName: 'Alice' | 'Bob') {
  // destroy the previous instance (if existing)
  if (currentAdaptableInstance) {
    const config: any = {
      unmount: true,
      destroyApi: true,
    };
    currentAdaptableInstance.destroy(config);
  }

  currentAdaptableInstance = await Adaptable.init(
    {
      ...getAdaptableOptionsForUser(userName, updateCurrentUser),
      // gridOptions: {...gridOptions},
    } as AdaptableOptions<WebFramework>,
    {
      gridOptions: {...gridOptions},
      modules: agGridModules,
    }
  );
  currentAdaptableInstance.eventApi.on(
    'AdaptableReady',
    (readyInfo: AdaptableReadyInfo) => {
      onAdaptableReady(readyInfo);
    }
  );
}

initializeAdaptable(currentUser);
```

**`src/App.tsx`** (React version)

```ts
import * as React from 'react';
import {useState} from 'react';
import {
  Adaptable,
  AdaptableApi,
  AdaptableReadyInfo,
} from '@adaptabletools/adaptable-react-aggrid';

// import adaptable css
import '@adaptabletools/adaptable-react-aggrid/index.css';
// import aggrid themes (using Balham theme)

import './styles.css';

import {onAdaptableReady} from './onAdaptableReady';
import {gridOptions} from './gridOptions';
import {agGridModules} from './agGridModules';
import {getAdaptableOptionsForUser} from './adaptableOptions';

const Grid = ({
  currentUser,
  onCurrentUserChange,
}: {
  currentUser: 'Alice' | 'Bob';
  onCurrentUserChange: (userName: 'Alice' | 'Bob') => void;
}) => {
  const adaptableApiRef = React.useRef<AdaptableApi>(null);

  const adaptableOptions = getAdaptableOptionsForUser(
    currentUser,
    onCurrentUserChange
  );

  const agGridOptions = {...gridOptions};
  return (
    <div style={{display: 'flex', flexFlow: 'column', height: '100vh'}}>
      <Adaptable.Provider
        gridOptions={agGridOptions}
        adaptableOptions={adaptableOptions}
        modules={[...agGridModules]}
        onAdaptableReady={(adaptableReadyInfo: AdaptableReadyInfo) => {
          // save a reference to adaptable api
          adaptableApiRef.current = adaptableReadyInfo.adaptableApi;
          onAdaptableReady(adaptableReadyInfo);
        }}>
        <Adaptable.UI key={`${currentUser}-ui`} style={{flex: 'none'}} />
        <Adaptable.AgGridReact />
      </Adaptable.Provider>
    </div>
  );
};

const App: React.FunctionComponent = () => {
  const [currentUser, setCurrentUser] = useState<'Alice' | 'Bob'>('Alice');

  return (
    <Grid
      key={currentUser}
      currentUser={currentUser}
      onCurrentUserChange={userName => setCurrentUser(userName)}
    />
  );
};
export default App;
```

**`src/app/app.component.ts`** (Angular version)

```ts
import {ChangeDetectorRef, Component, Inject} from '@angular/core';

import {AdaptableReadyInfo, AdaptableOptions} from '@adaptabletools/adaptable-angular-aggrid';
import {GridOptions} from 'ag-grid-enterprise';

// Adaptable styles
import '@adaptabletools/adaptable-angular-aggrid/index.css';

// AG Grid styles

import './styles.css';

// grid configuration
import {gridOptions} from './gridOptions';
import {agGridModules} from './agGridModules';
import {onAdaptableReady} from './onAdaptableReady';
import {getAdaptableOptionsForUser} from './adaptableOptions';
import {WebFramework} from './rowData';

@Component({
  standalone: false,
  selector: 'app-root',
  template: `
    <div id="demoOutputAbove"></div>
    <adaptable-provider
      *ngIf="isUpToDate"
      [adaptableOptions]="adaptableOpts"
      [gridOptions]="agGridOptions"
      [modules]="modules"
      (adaptableReady)="adaptableReady($event)"
      style="height: 100vh; width: 100vw;">
      <adaptable-ui style="flex: none"></adaptable-ui>
      <ag-grid-angular
        *adaptable="let adaptable"
        [gridOptions]="adaptable.gridOptions"
        [modules]="adaptable.modules"
        style="flex: 1">
      </ag-grid-angular>
    </adaptable-provider>
    <div id="demoOutputBelow"></div>
  `,
  styles: [
    `
      :host {
        height: 100vh;
        display: flex;
        flex-flow: column;
      }
    `,
  ],
})
export class AppComponent {
  adaptableOpts: AdaptableOptions<WebFramework>;
  agGridOptions: GridOptions<WebFramework>;
  modules = agGridModules;

  currentUser: 'Alice' | 'Bob';
  isUpToDate = true;

  constructor(
    @Inject(ChangeDetectorRef) private changeDetectorRef: ChangeDetectorRef
  ) {
    this.currentUser = 'Alice';
    this.adaptableOpts = getAdaptableOptionsForUser(
      this.currentUser,
      (user: 'Alice' | 'Bob') => this.setCurrentUser(user)
    );
    this.agGridOptions = {...gridOptions};
  }

  setCurrentUser(currentUser: 'Alice' | 'Bob') {
    this.isUpToDate = false;
    this.changeDetectorRef.detectChanges();

    this.currentUser = currentUser;
    this.initializeAdaptable();
    this.isUpToDate = true;
    this.changeDetectorRef.detectChanges();
  }

  initializeAdaptable() {
    this.adaptableOpts = getAdaptableOptionsForUser(
      this.currentUser,
      (user: 'Alice' | 'Bob') => this.setCurrentUser(user)
    );
    this.agGridOptions = {...gridOptions};
  }

  adaptableReady($event: AdaptableReadyInfo) {
    onAdaptableReady($event);
  }
}
```

**`src/App.vue`** (Vue version)

```ts
<template>
  <Grid
    :key="currentUser"
    :currentUser="currentUser"
    @currentUserChange="setCurrentUser" />
</template>

<script lang="ts">
import {ref, defineComponent} from 'vue';
import {
  AdaptableProvider,
  AdaptableAgGridVue,
  AdaptableUI,
} from '@adaptabletools/adaptable-vue3-aggrid';

import {onAdaptableReady} from './onAdaptableReady';
import {gridOptions} from './gridOptions';
import {agGridModules} from './agGridModules';
import {getAdaptableOptionsForUser} from './adaptableOptions';

const Grid = defineComponent({
  props: {
    currentUser: {
      type: String,
      required: true,
    },
  },
  emits: ['currentUserChange'],
  setup(props, {emit}) {
    const adaptableOptions = getAdaptableOptionsForUser(
      props.currentUser,
      userName => emit('currentUserChange', userName)
    );

    const agGridOptions = {...gridOptions};

    return {
      adaptableOptions,
      agGridOptions,
      agGridModules,
      onAdaptableReady,
    };
  },
  components: {
    AdaptableProvider,
    AdaptableAgGridVue,
    AdaptableUI,
  },
  template: `
    <AdaptableProvider
        :gridOptions="agGridOptions"
        :adaptableOptions="adaptableOptions"
        :modules="agGridModules"
        @onAdaptableReady="onAdaptableReady">
      <div style="display: flex; flex-direction: column; height: 100vh">
        <AdaptableUI :key="currentUser + '-ui'" style="flex: none" />
        <AdaptableAgGridVue style="flex: 1"  />
      </div>
    </AdaptableProvider>
  `,
});

export default defineComponent({
  name: 'App',
  components: {
    Grid,
  },
  setup() {
    const currentUser = ref('Alice');

    const setCurrentUser = userName => {
      currentUser.value = userName;
    };

    return {
      currentUser,
      setCurrentUser,
    };
  },
});
</script>
```
