Skip to content

Using the `HotColumn` component in Vue 3

Configure the Vue 3 data grid’s columns, using the props of the HotColumn component. Define a custom cell editor or a custom cell renderer.

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.

JavaScript
import { defineComponent } from 'vue';
import { HotTable, HotColumn } from '@handsontable/vue3';
import { registerAllModules } from 'handsontable/registry';
// register Handsontable's modules
registerAllModules();
const ExampleComponent = defineComponent({
data() {
return {
hotSettings: {
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',
},
secondColumnSettings: {
title: 'Second column header',
},
};
},
components: {
HotTable,
HotColumn,
}
});
export default ExampleComponent;
HTML
<div id="example1">
<hot-table :settings="hotSettings">
<hot-column title="First column header">
</hot-column>
<hot-column :settings="secondColumnSettings" read-only="true">
</hot-column>
</hot-table>
</div>

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.

JavaScript
import { defineComponent } from 'vue';
import { HotTable, HotColumn } from '@handsontable/vue3';
import { registerAllModules } from 'handsontable/registry';
// register Handsontable's modules
registerAllModules();
const ExampleComponent = defineComponent({
data() {
return {
hotData: [
{ 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' } }
],
secondColumnSettings: {
title: 'Second column header'
},
settings: {
height: 'auto',
autoWrapRow: true,
autoWrapCol: true,
licenseKey: 'non-commercial-and-evaluation'
},
};
},
components: {
HotTable,
HotColumn,
}
});
export default ExampleComponent;
HTML
<div id="example2">
<hot-table :data="hotData" :settings="settings">
<hot-column title="ID" data="id">
</hot-column>
<hot-column :settings="secondColumnSettings" read-only="true" data="name">
</hot-column>
<hot-column title="Price" data="payment.price">
</hot-column>
<hot-column title="Currency" data="payment.currency">
</hot-column>
</hot-table>
</div>

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.

JavaScript
import { defineComponent } from 'vue';
import { HotTable, HotColumn } from '@handsontable/vue3';
import { TextEditor } from 'handsontable/editors/textEditor';
import { registerAllModules } from 'handsontable/registry';
// register Handsontable's modules
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 ExampleComponent = defineComponent({
data() {
return {
customEditor: CustomEditor,
hotData: [
['A1', 'B1'],
['A2', 'B2'],
['A3', 'B3'],
['A4', 'B4'],
['A5', 'B5'],
],
settings: {
height: 'auto',
autoWrapRow: true,
autoWrapCol: true,
licenseKey: 'non-commercial-and-evaluation',
},
};
},
components: {
HotTable,
HotColumn,
}
});
export default ExampleComponent;
HTML
<div id="example3">
<hot-table :data="hotData" :settings="settings">
<hot-column title="Column A" :editor="customEditor">
</hot-column>
<hot-column title="Column B" :read-only="true">
</hot-column>
</hot-table>
</div>