Skip to content

Create interactive elements that can be checked or unchecked, by using the checkbox cell type.

Overview

Data in these cells will be rendered as a checkbox and you can easily change it by checking/unchecking the checkbox.

To check the box, use the mouse or press Space or Enter.

To uncheck the box, use the mouse or press Space, Enter, Delete or Backspace.

You can change the state of multiple cells at once by selecting the cells you want to change and pressing Space.

Checkbox true/false values

This is the default usage scenario where column data has a true or false value, and we only want to display checkboxes.

TypeScript
/* file: app.component.ts */
import { Component } from '@angular/core';
import { GridSettings } from '@handsontable/angular-wrapper';
@Component({
selector: 'example1-checkbox-cell-type',
standalone: false,
template: ` <div>
<hot-table [data]="data" [settings]="gridSettings"></hot-table>
</div>`,
})
export class Example1CheckboxCellTypeComponent {
readonly data = [
{
car: 'Mercedes A 160',
year: 2017,
available: true,
comesInBlack: 'yes',
},
{
car: 'Citroen C4 Coupe',
year: 2018,
available: false,
comesInBlack: 'yes',
},
{
car: 'Audi A4 Avant',
year: 2019,
available: true,
comesInBlack: 'no',
},
{
car: 'Opel Astra',
year: 2020,
available: false,
comesInBlack: 'yes',
},
{
car: 'BMW 320i Coupe',
year: 2021,
available: false,
comesInBlack: 'no',
},
];
readonly gridSettings: GridSettings = {
colHeaders: ['Car model', 'Year of manufacture', 'Available'],
height: 'auto',
autoWrapRow: true,
autoWrapCol: true,
columns: [
{
data: 'car',
},
{
data: 'year',
type: 'numeric',
},
{
data: 'available',
type: 'checkbox',
},
]
};
}
/* end-file */
/* 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';
/* start:skip-in-compilation */
import { Example1CheckboxCellTypeComponent } from './app.component';
/* end:skip-in-compilation */
// register Handsontable's modules
registerAllModules();
export const appConfig: ApplicationConfig = {
providers: [
{
provide: HOT_GLOBAL_CONFIG,
useValue: {
license: NON_COMMERCIAL_LICENSE,
} as HotGlobalConfig
}
],
};
@NgModule({
imports: [ BrowserModule, HotTableModule, CommonModule ],
declarations: [ Example1CheckboxCellTypeComponent ],
providers: [...appConfig.providers],
bootstrap: [ Example1CheckboxCellTypeComponent ]
})
export class AppModule { }
/* end-file */
HTML
<div>
<example1-checkbox-cell-type></example1-checkbox-cell-type>
</div>

Checkbox template

If you want to use values other than true and false, you have to provide this information using checkedTemplate and uncheckedTemplate. Handsontable will then update your data using the appropriate template.

TypeScript
/* file: app.component.ts */
import { Component } from '@angular/core';
import { GridSettings } from '@handsontable/angular-wrapper';
@Component({
selector: 'example2-checkbox-cell-type',
standalone: false,
template: ` <div>
<hot-table [data]="data" [settings]="gridSettings"></hot-table>
</div>`,
})
export class Example2CheckboxCellTypeComponent {
readonly data = [
{
car: 'Mercedes A 160',
year: 2017,
available: true,
comesInBlack: 'yes',
},
{
car: 'Citroen C4 Coupe',
year: 2018,
available: false,
comesInBlack: 'yes',
},
{
car: 'Audi A4 Avant',
year: 2019,
available: true,
comesInBlack: 'no',
},
{
car: 'Opel Astra',
year: 2020,
available: false,
comesInBlack: 'yes',
},
{
car: 'BMW 320i Coupe',
year: 2021,
available: false,
comesInBlack: 'no',
},
];
readonly gridSettings: GridSettings = {
colHeaders: ['Car model', 'Year of manufacture', 'Comes in black'],
height: 'auto',
autoWrapRow: true,
autoWrapCol: true,
columns: [
{
data: 'car',
},
{
data: 'year',
type: 'numeric',
},
{
data: 'comesInBlack',
type: 'checkbox',
checkedTemplate: 'yes',
uncheckedTemplate: 'no',
},
]
};
}
/* end-file */
/* 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';
/* start:skip-in-compilation */
import { Example2CheckboxCellTypeComponent } from './app.component';
/* end:skip-in-compilation */
// register Handsontable's modules
registerAllModules();
export const appConfig: ApplicationConfig = {
providers: [
{
provide: HOT_GLOBAL_CONFIG,
useValue: {
license: NON_COMMERCIAL_LICENSE,
} as HotGlobalConfig
}
],
};
@NgModule({
imports: [ BrowserModule, HotTableModule, CommonModule ],
declarations: [ Example2CheckboxCellTypeComponent ],
providers: [...appConfig.providers],
bootstrap: [ Example2CheckboxCellTypeComponent ]
})
export class AppModule { }
/* end-file */
HTML
<div>
<example2-checkbox-cell-type></example2-checkbox-cell-type>
</div>

Checkbox labels

To add a label to the checkbox, use the label option. You can declare where the label will be injected with this option - either before or after the checkbox element. You can also declare from which data source the label text will be updated.

TypeScript
/* file: app.component.ts */
import { Component } from '@angular/core';
import { GridSettings } from '@handsontable/angular-wrapper';
@Component({
selector: 'example3-checkbox-cell-type',
standalone: false,
template: ` <div>
<hot-table [data]="data" [settings]="gridSettings"></hot-table>
</div>`,
})
export class Example3CheckboxCellTypeComponent {
readonly data = [
{
car: 'Mercedes A 160',
year: 2017,
available: true,
comesInBlack: 'yes',
},
{
car: 'Citroen C4 Coupe',
year: 2018,
available: false,
comesInBlack: 'yes',
},
{
car: 'Audi A4 Avant',
year: 2019,
available: true,
comesInBlack: 'no',
},
{
car: 'Opel Astra',
year: 2020,
available: false,
comesInBlack: 'yes',
},
{
car: 'BMW 320i Coupe',
year: 2021,
available: false,
comesInBlack: 'no',
},
];
readonly gridSettings: GridSettings = {
colHeaders: ['Car model', 'Accepted', 'Comes in black'],
height: 'auto',
autoWrapRow: true,
autoWrapCol: true,
columns: [
{
data: 'car',
},
{
data: 'available',
type: 'checkbox',
label: {
position: 'after',
property: 'car', // Read value from row object
},
},
{
data: 'comesInBlack',
type: 'checkbox',
checkedTemplate: 'yes',
uncheckedTemplate: 'no',
label: {
position: 'before',
value: 'In black? ',
},
},
]
};
}
/* end-file */
/* 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';
/* start:skip-in-compilation */
import { Example3CheckboxCellTypeComponent } from './app.component';
/* end:skip-in-compilation */
// register Handsontable's modules
registerAllModules();
export const appConfig: ApplicationConfig = {
providers: [
{
provide: HOT_GLOBAL_CONFIG,
useValue: {
license: NON_COMMERCIAL_LICENSE,
} as HotGlobalConfig
}
],
};
@NgModule({
imports: [ BrowserModule, HotTableModule, CommonModule ],
declarations: [ Example3CheckboxCellTypeComponent ],
providers: [...appConfig.providers],
bootstrap: [ Example3CheckboxCellTypeComponent ]
})
export class AppModule { }
/* end-file */
HTML
<div>
<example3-checkbox-cell-type></example3-checkbox-cell-type>
</div>

Label value as a function

The value property of the label option can also be a function. The function receives four arguments: row, column, prop, and value, where value is the current cell value. This lets you generate label text dynamically based on the cell’s state.

TypeScript
/* file: app.component.ts */
import { Component } from '@angular/core';
import { GridSettings } from '@handsontable/angular-wrapper';
@Component({
selector: 'example4-checkbox-cell-type',
standalone: false,
template: ` <div>
<hot-table [data]="data" [settings]="gridSettings"></hot-table>
</div>`,
})
export class Example4CheckboxCellTypeComponent {
readonly data = [
{ car: 'Mercedes A 160', year: 2017, comesInBlack: 'yes' },
{ car: 'Citroen C4 Coupe', year: 2018, comesInBlack: 'yes' },
{ car: 'Audi A4 Avant', year: 2019, comesInBlack: 'no' },
{ car: 'Opel Astra', year: 2020, comesInBlack: 'yes' },
{ car: 'BMW 320i Coupe', year: 2021, comesInBlack: 'no' },
];
readonly gridSettings: GridSettings = {
colHeaders: ['Car model', 'Year', 'Comes in black'],
height: 'auto',
autoWrapRow: true,
autoWrapCol: true,
columns: [
{
data: 'car',
},
{
data: 'year',
},
{
data: 'comesInBlack',
type: 'checkbox',
checkedTemplate: 'yes',
uncheckedTemplate: 'no',
label: {
position: 'after',
value: function(
row: number,
column: number,
prop: string | number,
value: string
) {
if (value === 'yes') {
return 'In black';
} else {
return 'Not in black';
}
},
},
},
]
};
}
/* end-file */
/* 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';
/* start:skip-in-compilation */
import { Example4CheckboxCellTypeComponent } from './app.component';
/* end:skip-in-compilation */
// register Handsontable's modules
registerAllModules();
export const appConfig: ApplicationConfig = {
providers: [
{
provide: HOT_GLOBAL_CONFIG,
useValue: {
license: NON_COMMERCIAL_LICENSE,
} as HotGlobalConfig
}
],
};
@NgModule({
imports: [ BrowserModule, HotTableModule, CommonModule ],
declarations: [ Example4CheckboxCellTypeComponent ],
providers: [...appConfig.providers],
bootstrap: [ Example4CheckboxCellTypeComponent ]
})
export class AppModule { }
/* end-file */
HTML
<div>
<example4-checkbox-cell-type></example4-checkbox-cell-type>
</div>
WindowsmacOSActionExcelSheets
SpaceSpaceCheck or uncheck the checkbox
EnterEnterCheck or uncheck the checkbox
DeleteDeleteUncheck the checkbox
BackspaceBackspaceUncheck the checkbox

Related guides

Configuration options

Core methods

Hooks