This page covers a non-latest version of Handsontable.
# Custom context menu in Angular
# Overview
The following is an implementation of the @handsontable/angular
component with a custom context menu added.
# Example
// app.component.ts
import { Component } from '@angular/core';
import * as Handsontable from 'handsontable';
@Component({
selector: 'app-root',
template: `
<div>
<hot-table [settings]="hotSettings"></hot-table>
</div>
`,
})
class AppComponent {
hotSettings: Handsontable.GridSettings = {
data: Handsontable.helper.createSpreadsheetData(5, 5),
colHeaders: true,
contextMenu: {
items: {
'row_above': {
name: 'Insert row above this one (custom name)'
},
'row_below': {},
'separator': Handsontable.plugins.ContextMenu.SEPARATOR,
'clear_custom': {
name: 'Clear all cells (custom)',
callback: function() {
this.clear();
}
}
}
},
height: 'auto',
licenseKey: 'non-commercial-and-evaluation'
};
}
// app.module.ts
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { HotTableModule } from '@handsontable/angular';
@NgModule({
imports: [ BrowserModule, HotTableModule ],
declarations: [ AppComponent ],
bootstrap: [ AppComponent ]
})
class AppModule { }
// bootstrap
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
platformBrowserDynamic().bootstrapModule(AppModule).catch(err => { console.error(err) });