Handsontable example

by TonyNguyen001

HTML

<div id="example1">
  <div id="example-preview" class="hot">
    <div id="toggle-boxes">
    </div>
    <hot-table ref="wrapper" :settings="hotSettings"></hot-table>
  </div>
  <div id="vuex-preview">
  
    <h4 style="margin-bottom:10px;">Detail area</h4>
    <i style="color: red;"> If change data at detail area, i want it will be update on the table</i>
    <div>
      <label>A</label>
      <input v-model="detailData.a"></input>
    </div>
    <div>
      <label>B</label>
      <input v-model="detailData.b"></input>
    </div>
    <div>
      <label>C</label>
      <input v-model="detailData.c"></input>
    </div>
    <div>
      <label>D</label>
      <input v-model="detailData.d"></input>
    </div>
  </div>
</div>

CSS

</style>< !-- Ugly Hack due to jsFiddle issue --><script src="https://cdn.jsdelivr.net/npm/handsontable@7.4.2/dist/handsontable.full.min.js"></script><link type="text/css"rel="stylesheet"href="https://cdn.jsdelivr.net/npm/handsontable@7.4.2/dist/handsontable.full.min.css"><script src="https://handsontable.com/docs/7.4.2/scripts/jsfiddle-fixer.js"></script><script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.min.js"></script><script src="https://unpkg.com/vuex@3/dist/vuex.js"></script><script src="https://cdn.jsdelivr.net/npm/@handsontable/vue@4.1.1/dist/vue-handsontable.min.js"></script>

Babel + JSX

import Vue from 'vue';
  import { HotTable } from '@handsontable/vue';
  import Handsontable from 'handsontable';
  
  new Vue({
    el: "#example1",
    data: function() {
      return {
      	detailData: {},
        hotSettings: {
          data: [
          	{a: "A1", b: "B1", c: "C1", d: "D1"},
            {a: "A2", b: "B2", c: "C2", d: "D2"},
            {a: "A3", b: "B3", c: "C3", d: "D3"},
            {a: "A4", b: "B4", c: "C4", d: "D4"},
          ],
          colHeaders: true,
          rowHeaders: true,
          readOnly: false,
          afterChange: () => {
            if (this.hotRef) {
              this.$store.commit('updateData', this.hotRef.getSourceData());
            }
          },
          afterSelection: this.afterSelectionVue,
        },
        hotRef: null
      };
    },
    mounted: function() {
      this.hotRef = this.$refs.wrapper.hotInstance;
      this.detailData = this.hotRef.getSourceData()[0];
    },
    methods: {
			afterSelectionVue(row, col) {
      	this.detailData = this.hotRef.getSourceDataAtRow(row);
      }
      
    },
    components: {
      HotTable
    },
    store: new Vuex.Store({
      state: {
        hotData: null,
        hotSettings: {
          readOnly: false
        }
      },
      mutations: {
        updateData(state, hotData) {
          state.hotData = hotData;
        },
        updateSettings(state, updateObj) {
          state.hotSettings[updateObj.prop] = updateObj.value;
        }
      }
    })
  });