# Custom Reports

Canonical page: https://www.adaptabletools.com/docs/handbook-exporting-reports-custom

- AdapTable allows users to create Custom Reports
- These can be configured by developers at design-time, or build in the UI at run-time
- Custom Reports typically use an Expression
- Custom Reports can be exported in various formats to all destinations

Custom (i.e. bespoke) Reports can be provided to supplement the System Reports shipped by AdapTable.

Custom Reports can be created and supplied in 2 ways:
- by run-time users via the Export Wizard
- at design-time through Export Initial State 

AdapTable enables these reports to be exported to all available destinations.

Each Custom Report specifies which columns and rows to export.

Custom Report rows typically contain a [Boolean Expression](https://www.adaptabletools.com/docs/adaptable-ql-expression-standard/index.md), evaluated by [AdapTableQL](https://www.adaptabletools.com/docs/adaptable-ql-expression/index.md) each time the Report runs

**Example: Custom Reports**

Exporting Data from AdapTable via Custom-created Reports

 

- This demo contains 2 Custom Reports (provided in Export Initial State):
  - `Popular Frameworks` - exports 2 columns for rows with `Github Stars` > 50000
  - `MIT JavaScript` - exports 5 columns for rows where `Language` is *JavaScript* and the `License` is *MIT License*

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             [template]
  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} from '@adaptabletools/adaptable';
import {WebFramework} from './rowData';

export const adaptableOptions: AdaptableOptions<WebFramework> = {
  primaryKey: 'id',
  adaptableId: 'Custom Reports',
  initialState: {
    Dashboard: {
      Tabs: [
        {
          Name: 'Demo',
          Toolbars: ['Export'],
        },
      ],
      ModuleButtons: ['Export'],
    },
    StatusBar: {
      StatusBars: [
        {
          Key: 'Center Panel',
          StatusBarPanels: ['Export'],
        },
      ],
    },
    Theme: {CurrentTheme: 'dark'},
    Export: {
      CurrentReport: 'Popular Frameworks',
      CurrentFormat: 'JSON',
      Reports: [
        {
          Name: 'Popular Frameworks',
          ReportColumnScope: 'ScopeColumns',
          ReportRowScope: 'ExpressionRows',
          Scope: {ColumnIds: ['name', 'language']},
          Expression: '[github_stars] > 50000 ',
        },
        {
          Name: 'MIT JavaScript',
          ReportColumnScope: 'ScopeColumns',
          ReportRowScope: 'ExpressionRows',
          Scope: {
            ColumnIds: ['name', 'language', 'topics', 'license', 'updated_at'],
          },
          Expression: "[language] = 'JavaScript' AND [license] = 'MIT License'",
        },
      ],
    },
    Layout: {
      CurrentLayout: 'Standard Layout',
      Layouts: [
        {
          TableColumns: [
            'name',
            'language',
            'github_stars',
            'license',
            'has_projects',
            'has_pages',
            'created_at',
            'has_wiki',
            'updated_at',
            'pushed_at',
            'github_watchers',
            'week_issue_change',
          ],
          Name: 'Standard Layout',
          AutoSizeColumns: true,
        },
      ],
    },
  },
};
```

### Defining Custom Reports

Custom Reports can be provided at design-time in [Export Initial State](https://www.adaptabletools.com/docs/technical-reference-exporting/index.md).

### Defining a Custom Report

Follow these steps to define a Custom Report:

`ReportColumnScope` defines the Report's **columns**.

The available values are:
- *AllColumns* - every Column defined in AG Grid GridOptions
- *VisibleColumns* - every visible Column in the Grid
- *ScopeColumns* - bespoke Column list (defined separately)

```ts {5}
const initialState: InitialState = {
    Export: {
       Reports: [
        {
            ReportColumnScope: 'ScopeColumns',
            ReportRowScope: 'ExpressionRows',
            Scope: {ColumnIds: ['name', 'language']},
            Expression: '[github_stars]>50000',
            Name: 'Popular Frameworks',
        },
    ],
  },
}
```

If `ReportColumnScope` is set to *ScopeColumns*, then these must be listed separately in the `Scope` property.

This defines **which** Columns, Column Types or Data Types will be exported.

```ts {7}
const initialState: InitialState = {
    Export: {
       Reports: [
        {
            ReportColumnScope: 'ScopeColumns',
            ReportRowScope: 'ExpressionRows',
            Scope: {ColumnIds: ['name', 'language']},
            Expression: '[github_stars]>50000',
            Name: 'Popular Frameworks',
        },
    ],
  },
}
```

See [Scope](https://www.adaptabletools.com/docs/dev-guide-columns-scope/index.md) for a detailed look at this commonly used object

`ReportRowScope` defines the Report's **rows**.

The available values are:
- *AllRows* - every Row in AG Grid's data source
- *VisibleRows* - Rows currently in Grid (if not viewport)
- *ExpressionRows* - Rows returned by an [AdapTableQL](https://www.adaptabletools.com/docs/adaptable-ql-expression/index.md) Expression (see below)

```ts {6}
const initialState: InitialState = {
    Export: {
       Reports: [
        {
            ReportColumnScope: 'ScopeColumns',
            ReportRowScope: 'ExpressionRows',
            Scope: {ColumnIds: ['name', 'language']},
            Expression: '[github_stars]>50000',
            Name: 'Popular Frameworks',
        },
    ],
  },
}
```

If `ReportRowScope` is set to *ExpressionRows*, then the `Expression` property must also be provided.

This contains the [Expression](https://www.adaptabletools.com/docs/adaptable-ql-expression-standard/index.md) which will be evaluated by [AdapTableQL](https://www.adaptabletools.com/docs/adaptable-ql-expression/index.md) each time the Report is run.

```ts {8}
const initialState: InitialState = {
    Export: {
       Reports: [
        {
            ReportColumnScope: 'ScopeColumns',
            ReportRowScope: 'ExpressionRows',
            Scope: {ColumnIds: ['name', 'language']},
            Expression: '[github_stars]>50000',
            Name: 'Popular Frameworks',
        },
    ],
  },
}
```

Rows exported via an Expression do not need to be visible in the Grid when the Report runs, but do need to be in the underlying Data Set

Provide a unique, and easily identifiable name for the Report via the `Name` property.

This value will be used wherever the Report is referenced, e.g. in the Toolbar, Tool Panel or Export section of the Settings Panel.

```ts {9}
const initialState: InitialState = {
    Export: {
       Reports: [
        {
            ReportColumnScope: 'ScopeColumns',
            ReportRowScope: 'ExpressionRows',
            Scope: {ColumnIds: ['name', 'language']},
            Expression: '[github_stars]>50000',
            Name: 'Popular Frameworks',
        },
    ],
  },
}
```

### Using Custom Report Wizard

### Using the Export Wizard to Create / Edit Custom Reports

There are a few steps required for creating a Custom Report in the Export Wizard:

Select whether the Report should display:
- *All Columns* - every Column defined in AG Grid GridOptions
- *Visible Columns* - every visible Column in the Grid
- *Bespoke Columns* - a custom Column (or DataType) list 

If "Bespoke Columns" was selected in the previous step the Scope Component is displayed.

Here you can specify which Columns or DataTypes to export.

See Scope for a detailed look at this commonly used object

Select whether the Report should export:
- *All Rows* - every Row in AG Grid's data source
- *Visible Rows* - Rows currently in Grid (though not necessarily in the viewport)
- *By Expression* - only the Rows returned by an AdapTableQL Expression

If "By Expression" was selected in previous step, the Expression Editor is displayed.

This allows you to create a powerful, custom Boolean Expression. 

This will then be evaluated by AdapTableQL each time the Report is run.

Rows exported via an Expression need to be in the Data Set (but not the Grid) when the Report runs

See [AdapTableQL](https://www.adaptabletools.com/docs/adaptable-ql-expression/index.md)  for in-depth information on writing Expressions

Provide a unique, and easily identifiable name for the Custom Report via the `Name` property.

This value will be used wherever the Report is referenced, e.g. in the Toolbar, ToolPanel or Export section of the Settings Panel.
