Handsontable example

by Snowmee

HTML

<app-root></app-root>

CSS

</style><!-- Ugly Hack due to jsFiddle issue -->

<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/handsontable.full.min.js"></script>
<link type="text/css" rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/handsontable.full.min.css">
<script src="https://handsontable.com/docs/8.2.0/scripts/jsfiddle-fixer.js"></script>
<script src="https://cdn.jsdelivr.net/npm/rxjs@6/bundles/rxjs.umd.js"></script>
<script src="https://cdn.jsdelivr.net/npm/core-js@2/client/core.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/zone.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@angular/compiler@8/bundles/compiler.umd.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@angular/core@8/bundles/core.umd.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@angular/common@8/bundles/common.umd.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@angular/platform-browser@8/bundles/platform-browser.umd.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@angular/platform-browser-dynamic@8/bundles/platform-browser-dynamic.umd.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@handsontable/[email protected]/bundles/handsontable-angular.umd.min.js"></script>

TypeScript

// app.component.ts
  import { Component } from '@angular/core';
  import * as Handsontable from 'handsontable';
  import { HotTableComponent, HotTableRegisterer } from '@handsontable/angular';

  @Component({
    selector: 'app-root',
    template: `
    <div>
      <hot-table
        class="hot"
        [data]="dataset"
        [hotId]="id"
        [settings]="settings"
        [nestedRows]="true"
        [colHeaders]="true"
        [afterInit]="afterInitCallback"
        [rowHeaders]="true">
          <hot-column data="id" [readOnly]="true" title="ID"></hot-column>
          <hot-column data="name" title="Full name"></hot-column>
          <hot-column data="address" title="Street name"></hot-column>
      </hot-table>
    </div>
    
    <button (click)="changeSettings()">Change Settings</button>
    `,
  })
  class AppComponent {
    public afterInitCallback;
   	private hotRegisterer: HotTableRegisterer;
		public id="test1234";
    public settings={
    stretchH: 'none',
    }
    dataset: any[] = [
      {id: 1, name: 'Ted Right', address: 'Wall Street'},
      {id: 2, name: 'Frank Honest', address: 'Pennsylvania Avenue'},
      {id: 3, name: 'Joan Well', address: 'Broadway'},
      {id: 4, name: 'Gail Polite', address: 'Bourbon Street'},
      {id: 5, name: 'Michael Fair', address: 'Lombard Street'},
      {id: 6, name: 'Mia Fair', address: 'Rodeo Drive'},
      {id: 7, name: 'Cora Fair', address: 'Sunset Boulevard'},
      {id: 8, name: 'Jack Right', address: 'Michigan Avenue',
      	__children: [
       		{id: 1, name: 'Ted Right', address: 'Wall Street'},
      		{id: 2, name: 'Frank Honest', address: 'Pennsylvania Avenue'},
      		{id: 3, name: 'Joan Well', address: 'Broadway'},
      		{id: 4, name: 'Gail Polite', address: 'Bourbon Street'},
      		{id: 5, name: 'Michael Fair', address: 'Lombard Street'},
      		{id: 6, name: 'Mia Fair', address: 'Rodeo Drive'},
      		{id: 7, name: 'Cora Fair', address: 'Sunset Boulevard'},
      ]},
    ];
   ...