Column hiding
Hide individual columns to reduce screen clutter and improve the grid’s performance.
Overview
“Hiding a column” means that the hidden column doesn’t get rendered as a DOM element.
When you’re hiding a column:
- The source data doesn’t get modified.
- The
HiddenColumnsplugin doesn’t participate in data transformation
(the shape of the data returned by thegetData*()methods stays intact).
Enable column hiding
To enable column hiding, use the hiddenColumns option.
/* file: app.component.ts */import { Component } from '@angular/core';import { GridSettings } from '@handsontable/angular-wrapper';
@Component({ selector: 'app-example1', template: ` <hot-table [settings]="hotSettings!" [data]="hotData"> </hot-table> `, standalone: false})export class AppComponent {
readonly hotData = [ ['A1', 'B1', 'C1', 'D1', 'E1', 'F1', 'G1', 'H1', 'I1', 'J1', 'K1', 'L1'], ['A2', 'B2', 'C2', 'D2', 'E2', 'F2', 'G2', 'H2', 'I2', 'J2', 'K2', 'L2'], ['A3', 'B3', 'C3', 'D3', 'E3', 'F3', 'G3', 'H3', 'I3', 'J3', 'K3', 'L3'], ['A4', 'B4', 'C4', 'D4', 'E4', 'F4', 'G4', 'H4', 'I4', 'J4', 'K4', 'L4'], ['A5', 'B5', 'C5', 'D5', 'E5', 'F5', 'G5', 'H5', 'I5', 'J5', 'K5', 'L5'], ];
readonly hotSettings: GridSettings = { height: 'auto', colHeaders: true, rowHeaders: true, contextMenu: true, // enable the `HiddenColumns` plugin hiddenColumns: { columns: [2, 4, 6], indicators: true, }, autoWrapRow: true, autoWrapCol: true, };}/* 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 { AppComponent } from './app.component';/* end:skip-in-compilation */
// register Handsontable's modulesregisterAllModules();
export const appConfig: ApplicationConfig = { providers: [ { provide: HOT_GLOBAL_CONFIG, useValue: { license: NON_COMMERCIAL_LICENSE, } as HotGlobalConfig } ],};
@NgModule({ imports: [ BrowserModule, HotTableModule, CommonModule ], declarations: [ AppComponent ], providers: [...appConfig.providers], bootstrap: [ AppComponent ]})
export class AppModule { }/* end-file */<div> <app-example1></app-example1></div>Set up column hiding
To set up your column hiding configuration, follow the steps below.
Specify columns hidden by default
To both enable column hiding and specify columns hidden by default, set the
hiddenColumnsconfiguration option to an object.In the object, add a
columnsconfiguration option, and set it to an array of column indexes.Now, those columns are hidden by default:
TypeScript /* file: app.component.ts */import { Component } from '@angular/core';import { GridSettings } from '@handsontable/angular-wrapper';@Component({selector: 'app-example2',template: `<hot-table[settings]="hotSettings!" [data]="hotData"></hot-table>`,standalone: false})export class AppComponent {readonly hotData = [['A1', 'B1', 'C1', 'D1', 'E1', 'F1', 'G1', 'H1', 'I1', 'J1', 'K1', 'L1'],['A2', 'B2', 'C2', 'D2', 'E2', 'F2', 'G2', 'H2', 'I2', 'J2', 'K2', 'L2'],['A3', 'B3', 'C3', 'D3', 'E3', 'F3', 'G3', 'H3', 'I3', 'J3', 'K3', 'L3'],['A4', 'B4', 'C4', 'D4', 'E4', 'F4', 'G4', 'H4', 'I4', 'J4', 'K4', 'L4'],['A5', 'B5', 'C5', 'D5', 'E5', 'F5', 'G5', 'H5', 'I5', 'J5', 'K5', 'L5'],];readonly hotSettings: GridSettings = {height: 'auto',colHeaders: true,rowHeaders: true,// enable the `HiddenColumns` pluginhiddenColumns: {// specify columns hidden by defaultcolumns: [3, 5, 9],},autoWrapRow: true,autoWrapCol: true,};}/* 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 { AppComponent } from './app.component';/* end:skip-in-compilation */// register Handsontable's modulesregisterAllModules();export const appConfig: ApplicationConfig = {providers: [{provide: HOT_GLOBAL_CONFIG,useValue: {license: NON_COMMERCIAL_LICENSE,} as HotGlobalConfig}],};@NgModule({imports: [ BrowserModule, HotTableModule, CommonModule ],declarations: [ AppComponent ],providers: [...appConfig.providers],bootstrap: [ AppComponent ]})export class AppModule { }/* end-file */HTML <div><app-example2></app-example2></div>Show UI indicators
To easily see which columns are currently hidden, display UI indicators.
To enable the UI indicators, in the
hiddenColumnsobject, set theindicatorsproperty totrue:TypeScript /* file: app.component.ts */import { Component } from '@angular/core';import { GridSettings } from '@handsontable/angular-wrapper';@Component({selector: 'app-example3',template: `<hot-table[settings]="hotSettings!" [data]="hotData"></hot-table>`,standalone: false})export class AppComponent {readonly hotData = [['A1', 'B1', 'C1', 'D1', 'E1', 'F1', 'G1', 'H1', 'I1', 'J1', 'K1', 'L1'],['A2', 'B2', 'C2', 'D2', 'E2', 'F2', 'G2', 'H2', 'I2', 'J2', 'K2', 'L2'],['A3', 'B3', 'C3', 'D3', 'E3', 'F3', 'G3', 'H3', 'I3', 'J3', 'K3', 'L3'],['A4', 'B4', 'C4', 'D4', 'E4', 'F4', 'G4', 'H4', 'I4', 'J4', 'K4', 'L4'],['A5', 'B5', 'C5', 'D5', 'E5', 'F5', 'G5', 'H5', 'I5', 'J5', 'K5', 'L5'],];readonly hotSettings: GridSettings = {height: 'auto',colHeaders: true,rowHeaders: true,hiddenColumns: {columns: [3, 5, 9],// show UI indicators to mark hidden columnsindicators: true,},autoWrapRow: true,autoWrapCol: true,};}/* 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 { AppComponent } from './app.component';/* end:skip-in-compilation */// register Handsontable's modulesregisterAllModules();export const appConfig: ApplicationConfig = {providers: [{provide: HOT_GLOBAL_CONFIG,useValue: {license: NON_COMMERCIAL_LICENSE,} as HotGlobalConfig}],};@NgModule({imports: [ BrowserModule, HotTableModule, CommonModule ],declarations: [ AppComponent ],providers: [...appConfig.providers],bootstrap: [ AppComponent ]})export class AppModule { }/* end-file */HTML <div><app-example3></app-example3></div>Set up context menu items
To easily hide and unhide columns, add column hiding items to Handsontable’s context menu.
Enable both the
ContextMenuplugin and theHiddenColumnsplugin. Now, the context menu automatically displays additional items for hiding and unhiding columns.TypeScript /* file: app.component.ts */import { Component } from '@angular/core';import { GridSettings } from '@handsontable/angular-wrapper';@Component({selector: 'app-example4',template: `<hot-table[settings]="hotSettings!" [data]="hotData"></hot-table>`,standalone: false})export class AppComponent {readonly hotData = [['A1', 'B1', 'C1', 'D1', 'E1', 'F1', 'G1', 'H1', 'I1', 'J1', 'K1', 'L1'],['A2', 'B2', 'C2', 'D2', 'E2', 'F2', 'G2', 'H2', 'I2', 'J2', 'K2', 'L2'],['A3', 'B3', 'C3', 'D3', 'E3', 'F3', 'G3', 'H3', 'I3', 'J3', 'K3', 'L3'],['A4', 'B4', 'C4', 'D4', 'E4', 'F4', 'G4', 'H4', 'I4', 'J4', 'K4', 'L4'],['A5', 'B5', 'C5', 'D5', 'E5', 'F5', 'G5', 'H5', 'I5', 'J5', 'K5', 'L5'],];readonly hotSettings: GridSettings = {height: 'auto',colHeaders: true,rowHeaders: true,// enable the context menucontextMenu: true,// enable the `HiddenColumns` plugin// automatically adds the context menu's column hiding itemshiddenColumns: {columns: [3, 5, 9],indicators: true,},autoWrapRow: true,autoWrapCol: true,};}/* 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 { AppComponent } from './app.component';/* end:skip-in-compilation */// register Handsontable's modulesregisterAllModules();export const appConfig: ApplicationConfig = {providers: [{provide: HOT_GLOBAL_CONFIG,useValue: {license: NON_COMMERCIAL_LICENSE,} as HotGlobalConfig}],};@NgModule({imports: [ BrowserModule, HotTableModule, CommonModule ],declarations: [ AppComponent ],providers: [...appConfig.providers],bootstrap: [ AppComponent ]})export class AppModule { }/* end-file */HTML <div><app-example4></app-example4></div>You can also add the column hiding menu items individually, by adding the
hidden_columns_showandhidden_columns_hidestrings to thecontextMenuparameter:TypeScript /* file: app.component.ts */import { Component } from '@angular/core';import { GridSettings } from '@handsontable/angular-wrapper';@Component({selector: 'app-example5',template: `<hot-table[settings]="hotSettings!" [data]="hotData"></hot-table>`,standalone: false})export class AppComponent {readonly hotData = [['A1', 'B1', 'C1', 'D1', 'E1', 'F1', 'G1', 'H1', 'I1', 'J1', 'K1', 'L1'],['A2', 'B2', 'C2', 'D2', 'E2', 'F2', 'G2', 'H2', 'I2', 'J2', 'K2', 'L2'],['A3', 'B3', 'C3', 'D3', 'E3', 'F3', 'G3', 'H3', 'I3', 'J3', 'K3', 'L3'],['A4', 'B4', 'C4', 'D4', 'E4', 'F4', 'G4', 'H4', 'I4', 'J4', 'K4', 'L4'],['A5', 'B5', 'C5', 'D5', 'E5', 'F5', 'G5', 'H5', 'I5', 'J5', 'K5', 'L5'],];readonly hotSettings: GridSettings = {height: 'auto',colHeaders: true,rowHeaders: true,// individually add column hiding context menu itemscontextMenu: ['hidden_columns_show', 'hidden_columns_hide'],hiddenColumns: {columns: [3, 5, 9],indicators: true,},autoWrapRow: true,autoWrapCol: true,};}/* 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 { AppComponent } from './app.component';/* end:skip-in-compilation */// register Handsontable's modulesregisterAllModules();export const appConfig: ApplicationConfig = {providers: [{provide: HOT_GLOBAL_CONFIG,useValue: {license: NON_COMMERCIAL_LICENSE,} as HotGlobalConfig}],};@NgModule({imports: [ BrowserModule, HotTableModule, CommonModule ],declarations: [ AppComponent ],providers: [...appConfig.providers],bootstrap: [ AppComponent ]})export class AppModule { }/* end-file */HTML <div><app-example5></app-example5></div>Set up copy and paste behavior
By default, hidden columns are included in copying and pasting.
To exclude hidden columns from copying and pasting, in the
hiddenColumnsobject, set thecopyPasteEnabledproperty tofalse:TypeScript /* file: app.component.ts */import { Component } from '@angular/core';import { GridSettings } from '@handsontable/angular-wrapper';@Component({selector: 'app-example6',template: `<hot-table[settings]="hotSettings!" [data]="hotData"></hot-table>`,standalone: false})export class AppComponent {readonly hotData = [['A1', 'B1', 'C1', 'D1', 'E1', 'F1', 'G1', 'H1', 'I1', 'J1', 'K1', 'L1'],['A2', 'B2', 'C2', 'D2', 'E2', 'F2', 'G2', 'H2', 'I2', 'J2', 'K2', 'L2'],['A3', 'B3', 'C3', 'D3', 'E3', 'F3', 'G3', 'H3', 'I3', 'J3', 'K3', 'L3'],['A4', 'B4', 'C4', 'D4', 'E4', 'F4', 'G4', 'H4', 'I4', 'J4', 'K4', 'L4'],['A5', 'B5', 'C5', 'D5', 'E5', 'F5', 'G5', 'H5', 'I5', 'J5', 'K5', 'L5'],];readonly hotSettings: GridSettings = {height: 'auto',colHeaders: true,rowHeaders: true,contextMenu: ['hidden_columns_show', 'hidden_columns_hide'],hiddenColumns: {columns: [3, 5, 9],indicators: true,// exclude hidden columns from copying and pastingcopyPasteEnabled: false,},autoWrapRow: true,autoWrapCol: true,};}/* 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 { AppComponent } from './app.component';/* end:skip-in-compilation */// register Handsontable's modulesregisterAllModules();export const appConfig: ApplicationConfig = {providers: [{provide: HOT_GLOBAL_CONFIG,useValue: {license: NON_COMMERCIAL_LICENSE,} as HotGlobalConfig}],};@NgModule({imports: [ BrowserModule, HotTableModule, CommonModule ],declarations: [ AppComponent ],providers: [...appConfig.providers],bootstrap: [ AppComponent ]})export class AppModule { }/* end-file */HTML <div><app-example6></app-example6></div>
Column hiding API methods
For the most popular column hiding tasks, use the API methods below.
To see your changes, re-render your Handsontable instance with the
render() method.
Access the HiddenColumns plugin instance
To access the HiddenColumns plugin instance, use the
getPlugin() method:
const plugin = hot.getPlugin('hiddenColumns');Hide a single column
To hide a single column, use the hideColumn() method:
const plugin = hot.getPlugin('hiddenColumns');
plugin.hideColumn(4);
// re-render your Handsontable instancehot.render();Hide multiple columns
To hide multiple columns:
- Either pass column indexes as arguments to the
hideColumn()method - Or pass an array of column indexes to the
hideColumns()method
const plugin = hot.getPlugin('hiddenColumns');
plugin.hideColumn(0, 4, 6);// orplugin.hideColumns([0, 4, 6]);
// re-render your Handsontable instancehot.render();Unhide a single column
To unhide a single column, use the showColumn() method:
const plugin = hot.getPlugin('hiddenColumns');
plugin.showColumn(4);
// re-render your Handsontable instancehot.render();Unhide multiple columns
To unhide multiple columns:
- Either pass column indexes as arguments to the
showColumn()method - Or pass an array of column indexes to the
showColumns()method
const plugin = hot.getPlugin('hiddenColumns');
plugin.showColumn(0, 4, 6);// orplugin.showColumns([0, 4, 6]);
// re-render your Handsontable instancehot.render();Related API reference
Configuration options
Hooks
Plugins