Angular Data GridConfiguration options

Configure your grid down to each column, row, and cell, using various built-in options that control Handsontable's behavior and user interface.

Overview

To apply configuration options, pass them as GridSettings object to HotTableComponent.

import { GridSettings } from "@handsontable/angular-wrapper";

data = [
  ["A1", "B1", "C1", "D1"],
  ["A2", "B2", "C2", "D2"],
  ["A3", "B3", "C3", "D3"],
];
gridSettings: GridSettings = {
  autoWrapRow: true,
  autoWrapCol: true,
  width: 400,
  height: 300,
  colHeaders: true,
  rowHeaders: true,
  customBorders: true,
  dropdownMenu: true,
  multiColumnSorting: true,
  filters: true,
  manualRowMove: true,
};
<hot-table [data]="data" [settings]="gridSettings" />

Depending on your needs, you can apply configuration options to different elements of your grid, such as:

For the full list of available configuration options, see the configuration options' API reference.

Cascading configuration

Handsontable's configuration cascades down:

When you modify the mid-level column options (using the columns option):

  • The options that you change overwrite the top-level grid options.
  • The options that you change cascade down to the bottom-level cell options.
  • Any unchanged options are inherited from the top-level grid options.

When you modify the bottom-level cell options (using the cell option):

  • The options that you change overwrite the top-level grid options.
  • The options that you change overwrite the mid-level column options.
  • Any unchanged options are inherited from the mid-level column options or the top-level grid options.

When you modify any options with the cells function, the changes overwrite all other options.

TIP

The cells option is a function invoked before Handsontable's rendering cycle. Implemented incorrectly, it can slow Handsontable down. Use the cells option only if the cell option, the columns option, and the setCellMeta() method don't meet your needs.

For more details on Handsontable's cascading configuration, see the MetaManager class (opens new window).

Plugin options

Configuration options can come from:

If you use Handsontable through modules: to use an option that comes from a Handsontable plugin, you need to import and register that plugin when initializing your Handsontable instance.

To find out if an option comes from a plugin, check the Category label in the configuration options' API reference.

Set grid options

To apply configuration options to the entire grid, pass your options as GridSettings object to HotTableComponent.

For example, to set the entire grid's width and height:

import { GridSettings } from "@handsontable/angular-wrapper";

gridSettings: GridSettings = {
  width: 400,
  height: 300,
};
<hot-table [settings]="gridSettings" />

Example

To configure each cell in the grid as read-only, apply the readOnly option as a top-level grid option.

The top-level grid options cascade down:

  • To the mid-level column options
  • To the bottom-level cell options

As a result, each cell in the grid is read-only:

/* file: app.component.ts */
import { Component } from '@angular/core';
import { GridSettings } from '@handsontable/angular-wrapper';
import Handsontable from 'handsontable';

@Component({
  selector: 'example1-configuration-options',
  standalone: false,
  template: ` <div>
    <hot-table [data]="data" [settings]="gridSettings"></hot-table>
  </div>`,
})
export class Example1ConfigurationOptionsComponent {

  readonly data: Handsontable.CellValue[][] = [
    ['A1', 'B1', 'C1', 'D1', 'E1', 'F1', 'G1', 'H1', 'I1', 'J1'],
    ['A2', 'B2', 'C2', 'D2', 'E2', 'F2', 'G2', 'H2', 'I2', 'J2'],
    ['A3', 'B3', 'C3', 'D3', 'E3', 'F3', 'G3', 'H3', 'I3', 'J3'],
    ['A4', 'B4', 'C4', 'D4', 'E4', 'F4', 'G4', 'H4', 'I4', 'J4'],
    ['A5', 'B5', 'C5', 'D5', 'E5', 'F5', 'G5', 'H5', 'I5', 'J5'],
  ];

  readonly gridSettings: GridSettings = {
    autoWrapRow: true,
    autoWrapCol: true,
    readOnly: true,
    width: 'auto',
    height: 'auto',
    rowHeaders: true,
    colHeaders: true
  };
}



/* file: app.module.ts */
import { NgModule, ApplicationConfig } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { registerAllModules } from 'handsontable/registry';
import { HOT_GLOBAL_CONFIG, HotGlobalConfig, HotTableModule } from '@handsontable/angular-wrapper';
import { CommonModule } from '@angular/common';
import { NON_COMMERCIAL_LICENSE } from '@handsontable/angular-wrapper';
import { Example1ConfigurationOptionsComponent } from './app.component';

// register Handsontable's modules
registerAllModules();

export const appConfig: ApplicationConfig = {
  providers: [
    {
      provide: HOT_GLOBAL_CONFIG,
      useValue: {
        themeName: 'ht-theme-main',
        license: NON_COMMERCIAL_LICENSE,
      } as HotGlobalConfig
    }
  ],
};

@NgModule({
  imports: [ BrowserModule, HotTableModule, CommonModule ],
  declarations: [ Example1ConfigurationOptionsComponent ],
  providers: [...appConfig.providers],
  bootstrap: [ Example1ConfigurationOptionsComponent ]
})

export class AppModule { }

Set column options

To apply configuration options to an individual column (or a range of columns), use the columns option.

import { GridSettings } from "@handsontable/angular-wrapper";

gridSettings: GridSettings = {
  columns: [
    { width: 100 }, // column options for the first (by physical index) column
    { width: 100 }, // column options for the second (by physical index) column
    { width: 100 }, // column options for the third (by physical index) column
  ],
};
<hot-table [settings]="gridSettings" />

Example

In the example below, the columns option is set to a function.

The function applies the readOnly: true option to each column that has a physical index of either 2 or 8.

The modified mid-level column options:

  • Overwrite the top-level grid options
  • Cascade down to the bottom-level cell options

As a result, each cell in the third and ninth columns is read-only:

/* file: app.component.ts */
import { Component } from '@angular/core';
import { GridSettings } from '@handsontable/angular-wrapper';
import Handsontable from 'handsontable';

@Component({
  selector: 'example2-configuration-options',
  standalone: false,
  template: ` <div>
    <hot-table [data]="data" [settings]="gridSettings"></hot-table>
  </div>`,
})
export class Example2ConfigurationOptionsComponent {

  readonly data: Handsontable.CellValue[][] = [
    ['A1', 'B1', 'C1', 'D1', 'E1', 'F1', 'G1', 'H1', 'I1', 'J1'],
    ['A2', 'B2', 'C2', 'D2', 'E2', 'F2', 'G2', 'H2', 'I2', 'J2'],
    ['A3', 'B3', 'C3', 'D3', 'E3', 'F3', 'G3', 'H3', 'I3', 'J3'],
    ['A4', 'B4', 'C4', 'D4', 'E4', 'F4', 'G4', 'H4', 'I4', 'J4'],
    ['A5', 'B5', 'C5', 'D5', 'E5', 'F5', 'G5', 'H5', 'I5', 'J5'],
  ];

  readonly gridSettings: GridSettings = {
    autoWrapRow: true,
    autoWrapCol: true,
    readOnly: false,
    width: 'auto',
    height: 'auto',
    rowHeaders: true,
    colHeaders: true,
    columns: (index: number) => ({
      type: index > 0 ? 'numeric' : 'text',
      readOnly: index === 2 || index === 8,
    })
  };
}



/* file: app.module.ts */
import { NgModule, ApplicationConfig } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { registerAllModules } from 'handsontable/registry';
import { HOT_GLOBAL_CONFIG, HotGlobalConfig, HotTableModule } from '@handsontable/angular-wrapper';
import { CommonModule } from '@angular/common';
import { NON_COMMERCIAL_LICENSE } from '@handsontable/angular-wrapper';
import { Example2ConfigurationOptionsComponent } from './app.component';

// register Handsontable's modules
registerAllModules();

export const appConfig: ApplicationConfig = {
  providers: [
    {
      provide: HOT_GLOBAL_CONFIG,
      useValue: {
        themeName: 'ht-theme-main',
        license: NON_COMMERCIAL_LICENSE,
      } as HotGlobalConfig
    }
  ],
};

@NgModule({
  imports: [ BrowserModule, HotTableModule, CommonModule ],
  declarations: [ Example2ConfigurationOptionsComponent ],
  providers: [...appConfig.providers],
  bootstrap: [ Example2ConfigurationOptionsComponent ]
})

export class AppModule { }

Set row options

To apply configuration options to an individual row (or a range of rows), use the cells option.

Any options modified through cells overwrite all other options.

The function can take three arguments:

  • row: a row coordinate (a physical index)
  • col: a column coordinate (a physical index)
  • prop: if your data is an array of objects, prop is a property name for a column's data source object.
    If your data is an array of arrays, prop is the same as col.
import { GridSettings } from "@handsontable/angular-wrapper";

gridSettings: GridSettings = {
  cells: (row, col, prop) => {
    if (row === 1 || row === 4) {
      return {
        // row options, which apply to each cell of the second row
        // and to each cell of the fifth row
        readOnly: true,
      };
    }
  },
};
<hot-table [settings]="gridSettings" />

Example

In the example below, the cells option sets each cell in the first and fourth row as readOnly.

Options modified through cells overwrite all other options.

/* file: app.component.ts */
import { Component } from '@angular/core';
import { GridSettings } from '@handsontable/angular-wrapper';
import Handsontable from 'handsontable';

@Component({
  selector: 'example3-configuration-options',
  standalone: false,
  template: ` <div>
    <hot-table [data]="data" [settings]="gridSettings"></hot-table>
  </div>`,
})
export class Example3ConfigurationOptionsComponent {

  readonly data: Handsontable.CellValue[][] = [
    ['A1', 'B1', 'C1', 'D1', 'E1', 'F1', 'G1', 'H1', 'I1', 'J1'],
    ['A2', 'B2', 'C2', 'D2', 'E2', 'F2', 'G2', 'H2', 'I2', 'J2'],
    ['A3', 'B3', 'C3', 'D3', 'E3', 'F3', 'G3', 'H3', 'I3', 'J3'],
    ['A4', 'B4', 'C4', 'D4', 'E4', 'F4', 'G4', 'H4', 'I4', 'J4'],
    ['A5', 'B5', 'C5', 'D5', 'E5', 'F5', 'G5', 'H5', 'I5', 'J5'],
  ];

  readonly gridSettings: GridSettings = {
    autoWrapRow: true,
    autoWrapCol: true,
    readOnly: false,
    width: 'auto',
    height: 'auto',
    rowHeaders: true,
    colHeaders: true,
    cells: (row: number, col: number) => {
      if (row === 1 || row === 4) {
        return { readOnly: true };
      }

      return {};
    }
  };
}



/* file: app.module.ts */
import { NgModule, ApplicationConfig } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { registerAllModules } from 'handsontable/registry';
import { HOT_GLOBAL_CONFIG, HotGlobalConfig, HotTableModule } from '@handsontable/angular-wrapper';
import { CommonModule } from '@angular/common';
import { NON_COMMERCIAL_LICENSE } from '@handsontable/angular-wrapper';
import { Example3ConfigurationOptionsComponent } from './app.component';

// register Handsontable's modules
registerAllModules();

export const appConfig: ApplicationConfig = {
  providers: [
    {
      provide: HOT_GLOBAL_CONFIG,
      useValue: {
        themeName: 'ht-theme-main',
        license: NON_COMMERCIAL_LICENSE,
      } as HotGlobalConfig
    }
  ],
};

@NgModule({
  imports: [ BrowserModule, HotTableModule, CommonModule ],
  declarations: [ Example3ConfigurationOptionsComponent ],
  providers: [...appConfig.providers],
  bootstrap: [ Example3ConfigurationOptionsComponent ]
})

export class AppModule { }

Set cell options

To apply configuration options to individual cells, use the cell option.

import { GridSettings } from "@handsontable/angular-wrapper";

gridSettings: GridSettings = {
  cell: [
    {
      // bottom-level cell options overwrite the top-level grid options
      // apply only to a cell with coordinates (0, 0)
      row: 0,
      col: 0,
    },
    {
      // bottom-level cell options overwrite the top-level grid options
      // apply only to a cell with coordinates (1, 1)
      row: 1,
      col: 1,
    },
  ],
};
<hot-table [settings]="gridSettings" />

Example

In the example below, the cell option sets cell A1(0, 0) and cell B2(1, 1) as readOnly.

The modified cell options:

  • Overwrite the top-level grid options
  • Overwrite mid-level column options

/* file: app.component.ts */
import { Component } from '@angular/core';
import { GridSettings } from '@handsontable/angular-wrapper';
import Handsontable from 'handsontable';

@Component({
  selector: 'example4-configuration-options',
  standalone: false,
  template: ` <div>
    <hot-table [data]="data" [settings]="gridSettings"></hot-table>
  </div>`,
})
export class Example4ConfigurationOptionsComponent {

  readonly data: Handsontable.CellValue[][] = [
    ['A1', 'B1', 'C1', 'D1', 'E1', 'F1', 'G1', 'H1', 'I1', 'J1'],
    ['A2', 'B2', 'C2', 'D2', 'E2', 'F2', 'G2', 'H2', 'I2', 'J2'],
    ['A3', 'B3', 'C3', 'D3', 'E3', 'F3', 'G3', 'H3', 'I3', 'J3'],
    ['A4', 'B4', 'C4', 'D4', 'E4', 'F4', 'G4', 'H4', 'I4', 'J4'],
    ['A5', 'B5', 'C5', 'D5', 'E5', 'F5', 'G5', 'H5', 'I5', 'J5'],
  ];

  readonly gridSettings: GridSettings = {
    autoWrapRow: true,
    autoWrapCol: true,
    readOnly: false,
    width: 'auto',
    height: 'auto',
    rowHeaders: true,
    colHeaders: true,
    cell: [
      {
        // bottom-level cell options overwrite the top-level grid options
        // apply only to a cell with coordinates (0, 0)
        row: 0,
        col: 0,
        readOnly: true,
      },
      {
        // bottom-level cell options overwrite the top-level grid options
        // apply only to a cell with coordinates (1, 1)
        row: 1,
        col: 1,
        readOnly: true,
      },
    ]
  };
}



/* file: app.module.ts */
import { NgModule, ApplicationConfig } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { registerAllModules } from 'handsontable/registry';
import { HOT_GLOBAL_CONFIG, HotGlobalConfig, HotTableModule } from '@handsontable/angular-wrapper';
import { CommonModule } from '@angular/common';
import { NON_COMMERCIAL_LICENSE } from '@handsontable/angular-wrapper';
import { Example4ConfigurationOptionsComponent } from './app.component';

// register Handsontable's modules
registerAllModules();

export const appConfig: ApplicationConfig = {
  providers: [
    {
      provide: HOT_GLOBAL_CONFIG,
      useValue: {
        themeName: 'ht-theme-main',
        license: NON_COMMERCIAL_LICENSE,
      } as HotGlobalConfig
    }
  ],
};

@NgModule({
  imports: [ BrowserModule, HotTableModule, CommonModule ],
  declarations: [ Example4ConfigurationOptionsComponent ],
  providers: [...appConfig.providers],
  bootstrap: [ Example4ConfigurationOptionsComponent ]
})

export class AppModule { }

Read cell options

When Handsontable is running, you can check a cell's current options, using the getCellMeta() method.

The getCellMeta() method returns an object with:

For example:

@ViewChild(HotTableComponent, { static: false }) readonly hotTable!: HotTableComponent;

import { GridSettings } from "@handsontable/angular-wrapper";

// Consider the HotTable component with the `cell` option declared:
gridSettings: GridSettings = {
  cell: [
    {
      row: 1,
      col: 1,
      readOnly: true,
    },
  ]
};

// for cell (0, 0), the `readOnly` option is the default (`false`)
// returns `false`
hotTable.hotInstance.getCellMeta(0, 0).readOnly;

// for cell (1, 1), the `cell` option overwrote the default `readOnly` value
// returns `true`
hotTable.hotInstance.getCellMeta(1, 1).readOnly;
<hot-table [settings]="gridSettings" />

Change cell options

When Handsontable is running, you can change the initial cell options, using the setCellMeta() method.

For example:

@ViewChild(HotTableComponent, { static: false }) readonly hotTable!: HotTableComponent;

import { GridSettings } from "@handsontable/angular-wrapper";

// Consider the HotTable component with the `cell` option declared:
gridSettings: GridSettings = {
  cell: [
    {
      row: 1,
      col: 1,
      readOnly: true,
    },
  ]
};

// changes the `readOnly` option of cell (1, 1) back to `false`
hotTable.hotInstance.setCellMeta(1, 1, "readOnly", false);

// returns `false`
hotTable.hotInstance.getCellMeta(1, 1).readOnly;
<hot-table [settings]="gridSettings" />

Implement custom logic

You can apply configuration options to individual grid elements (columns, rows, cells), based on any logic you implement, using the cells option.

The cells option overwrites all other options.

The function can take three arguments:

  • row: a row coordinate (a physical index)
  • col: a column coordinate (a physical index)
  • prop: if your data is an array of objects, prop is a property name for a column's data source object.
    If your data is an array of arrays, prop is the same as col.
import { GridSettings } from "@handsontable/angular-wrapper";

gridSettings: GridSettings = {
  cells: (row, col) => {
    if ((row === 1 || row === 5) && col === 1) {
      return {
        readOnly: true,
      };
    }
  },
};
<hot-table [settings]="gridSettings" />

Example

In the example below, the modified cells options overwrite the top-level grid options.

// for cell (0, 0), the `readOnly` option is the default (`false`)
// returns `false`
hot.getCellMeta(0, 0).readOnly;

// for cell (1, 1), the `cell` option overwrote the default `readOnly` value
// returns `true`
hot.getCellMeta(1, 1).readOnly;

// changes the `readOnly` option of cell (1, 1) back to `false`
hot.setCellMeta(1, 1, 'readOnly', false);

// returns `false`
hot.getCellMeta(1, 1).readOnly;

Configuration example

In the example below, some cells are read-only, and some cells are editable:

  • By default, all cells are read-only (as set in the top-level grid options).
  • For the first column, the mid-level column options overwrite the top-level grid options.
    As a result, the first column cells are editable.
  • For cell A1 (0, 0), the bottom-level cell options overwrite both the mid-level column options, and the top-level grid options.
    As a result, cell A1 (0, 0) is read-only, despite being part of the editable first column.
  • For cell C3 (3, 3), the cells option overwrites all other options.
    As a result, cell C3 (3, 3) is editable, despite not being part of the editable first column.

/* file: app.component.ts */
import { Component } from '@angular/core';
import { GridSettings } from '@handsontable/angular-wrapper';
import Handsontable from 'handsontable';

@Component({
  selector: 'example6-configuration-options',
  standalone: false,
  template: ` <div>
    <hot-table [data]="data" [settings]="gridSettings"></hot-table>
  </div>`,
})
export class Example6ConfigurationOptionsComponent {

  readonly data: Handsontable.CellValue[][] = [
    ['A1', 'B1', 'C1', 'D1', 'E1', 'F1', 'G1', 'H1', 'I1', 'J1'],
    ['A2', 'B2', 'C2', 'D2', 'E2', 'F2', 'G2', 'H2', 'I2', 'J2'],
    ['A3', 'B3', 'C3', 'D3', 'E3', 'F3', 'G3', 'H3', 'I3', 'J3'],
    ['A4', 'B4', 'C4', 'D4', 'E4', 'F4', 'G4', 'H4', 'I4', 'J4'],
    ['A5', 'B5', 'C5', 'D5', 'E5', 'F5', 'G5', 'H5', 'I5', 'J5'],
  ];

  readonly gridSettings: GridSettings = {
    autoWrapRow: true,
    autoWrapCol: true,
    readOnly: true,
    width: 'auto',
    height: 'auto',
    rowHeaders: true,
    colHeaders: true,
    columns: [
      // each cell in the first (by physical index) column is editable
      { readOnly: false, className: '' },
      {},
      {},
      {},
      {},
      {},
      {},
      {},
      {},
      {},
    ],
    cell: [
      // cell (0, 0) is read-only
      { row: 0, col: 0, readOnly: true },
    ],
    cells: (row: number, col: number) => {
      // cell (2, 2) is editable
      if (row === 2 && col === 2) {
        return { readOnly: false, className: '' };
      }

      return {};
    }
  };
}



/* file: app.module.ts */
import { NgModule, ApplicationConfig } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { registerAllModules } from 'handsontable/registry';
import { HOT_GLOBAL_CONFIG, HotGlobalConfig, HotTableModule } from '@handsontable/angular-wrapper';
import { CommonModule } from '@angular/common';
import { NON_COMMERCIAL_LICENSE } from '@handsontable/angular-wrapper';
import { Example6ConfigurationOptionsComponent } from './app.component';

// register Handsontable's modules
registerAllModules();

export const appConfig: ApplicationConfig = {
  providers: [
    {
      provide: HOT_GLOBAL_CONFIG,
      useValue: {
        themeName: 'ht-theme-main',
        license: NON_COMMERCIAL_LICENSE,
      } as HotGlobalConfig
    }
  ],
};

@NgModule({
  imports: [ BrowserModule, HotTableModule, CommonModule ],
  declarations: [ Example6ConfigurationOptionsComponent ],
  providers: [...appConfig.providers],
  bootstrap: [ Example6ConfigurationOptionsComponent ]
})

export class AppModule { }