Using the `HotColumn` component in Vue 3
HotColumn is a Vue 3 component that lets you define column settings declaratively as child components of HotTable.
Find out which Vue 3 versions are supported
Declare column settings
To declare column-specific settings, pass the settings as hot-column properties, either separately or wrapped as a settings property, exactly as you would for hot-table.
<script setup>import { ref } from 'vue';import { HotTable, HotColumn } from '@handsontable/vue3';import { registerAllModules } from 'handsontable/registry';
registerAllModules();
const hotSettings = ref({ data: [ ['A1', 'B1'], ['A2', 'B2'], ['A3', 'B3'], ['A4', 'B4'], ['A5', 'B5'], ['A6', 'B6'], ['A7', 'B7'], ['A8', 'B8'], ['A9', 'B9'], ['A10', 'B10'], ], height: 'auto', autoWrapRow: true, autoWrapCol: true, licenseKey: 'non-commercial-and-evaluation',});const secondColumnSettings = ref({ title: 'Second column header',});</script>
<template> <div id="example1"> <HotTable :settings="hotSettings"> <HotColumn title="First column header" /> <HotColumn :settings="secondColumnSettings" read-only="true" /> </HotTable> </div></template>Array of objects
To work with an array of objects for the hot-column component, you need to provide precise information about the data structure for the columns. To do this, refer to the data for a column in properties as data.
<script setup>import { ref } from 'vue';import { HotTable, HotColumn } from '@handsontable/vue3';import { registerAllModules } from 'handsontable/registry';
registerAllModules();
const hotData = ref([ { id: 1, name: 'Table tennis racket', payment: { price: 13, currency: 'PLN' } }, { id: 2, name: 'Outdoor game ball', payment: { price: 14, currency: 'USD' } }, { id: 3, name: 'Mountain bike', payment: { price: 300, currency: 'USD' } }]);const secondColumnSettings = ref({ title: 'Second column header'});const settings = ref({ height: 'auto', autoWrapRow: true, autoWrapCol: true, licenseKey: 'non-commercial-and-evaluation'});</script>
<template> <div id="example2"> <HotTable :data="hotData" :settings="settings"> <HotColumn title="ID" data="id" /> <HotColumn :settings="secondColumnSettings" read-only="true" data="name" /> <HotColumn title="Price" data="payment.price" /> <HotColumn title="Currency" data="payment.currency" /> </HotTable> </div></template>Declare a custom editor as a component
You can declare a custom editor by creating a class that extends TextEditor and passing it to a hot-column via the editor prop. The editor’s input element uses a placeholder attribute to display a hint when the cell value is empty.
<script setup>import { ref } from 'vue';import { HotTable, HotColumn } from '@handsontable/vue3';import { TextEditor } from 'handsontable/editors/textEditor';import { registerAllModules } from 'handsontable/registry';
registerAllModules();
class CustomEditor extends TextEditor { createElements() { super.createElements();
this.TEXTAREA = document.createElement('input'); this.TEXTAREA.setAttribute('placeholder', 'Custom placeholder'); this.TEXTAREA.setAttribute('data-hot-input', true); this.textareaStyle = this.TEXTAREA.style; this.TEXTAREA_PARENT.innerText = ''; this.TEXTAREA_PARENT.appendChild(this.TEXTAREA); }}
const customEditor = CustomEditor;const hotData = ref([ ['A1', 'B1'], ['A2', 'B2'], ['A3', 'B3'], ['A4', 'B4'], ['A5', 'B5'],]);const settings = ref({ height: 'auto', autoWrapRow: true, autoWrapCol: true, licenseKey: 'non-commercial-and-evaluation',});</script>
<template> <div id="example3"> <HotTable :data="hotData" :settings="settings"> <HotColumn title="Column A" :editor="customEditor" /> <HotColumn title="Column B" :read-only="true" /> </HotTable> </div></template>Result
Using HotColumn child components, each column reads its settings declaratively from Vue props rather than from a flat columns array, keeping your template in sync with your column configuration.