Custom editor in Vue 3
In this tutorial, you will create a custom cell editor as a Vue 3 component. You will learn to extend the BaseEditor class and register your editor with Handsontable.
Overview
You can declare a custom editor for the HotTable component by declaring it as a class and passing it to the Handsontable options or creating an editor component. You can use it many times and with different properties. To differentiate between editor instances, pass a key attribute.
Find out which Vue 3 versions are supported
Example - Declaring an editor as a class
The following example implements the @handsontable/vue3 component with a custom editor added, utilizing the placeholder attribute in the editor’s input element.
import { defineComponent } from 'vue';import { HotTable } from '@handsontable/vue3';import { TextEditor } from 'handsontable/editors/textEditor';import { registerAllModules } from 'handsontable/registry';
// register Handsontable's modulesregisterAllModules();
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 { hotSettings: { startRows: 5, columns: [ { editor: CustomEditor } ], colHeaders: true, colWidths: 200, autoWrapRow: true, autoWrapCol: true, height: 'auto', licenseKey: 'non-commercial-and-evaluation' } }; }, components: { HotTable, }});
export default ExampleComponent;<div id="example1"> <hot-table :settings="hotSettings"></hot-table></div>Related articles
Related guides
APIs
Configuration options
Core methods
Hooks
What you learned
- How to extend the
BaseEditorclass to build a custom editor. - How to register a custom editor with a Handsontable column or the entire grid.
- How to pass a
keyattribute to differentiate between multiple editor instances.
Next steps
- Cell editor — read the full editor API documentation.
- HotColumn component in Vue 3 — declare editors per column using HotColumn.
- Custom renderer in Vue 3 — complement your editor with a custom renderer.