Custom renderer in Vue 3
Create a custom cell renderer, and use it in your Vue 3 data grid by declaring it as a function.
Overview
You can declare a custom renderer for the HotTable component by declaring it as a function in the Handsontable options or creating a rendering component.
Find out which Vue 3 versions are supported
Declare a renderer as a function
The following example is an implementation of @handsontable/vue3 with a custom renderer added. It takes an image URL as the input and renders the image in the edited cell.
import { defineComponent } from 'vue';import { HotTable } from '@handsontable/vue3';import { registerAllModules } from 'handsontable/registry';
// register Handsontable's modulesregisterAllModules();
const ExampleComponent = defineComponent({ data() { return { hotSettings: { data: [ ['A1', '/docs/img/examples/professional-javascript-developers-nicholas-zakas.jpg'], ['A2', '/docs/img/examples/javascript-the-good-parts.jpg'] ], columns: [ {}, { renderer(instance, td, row, col, prop, value) { const img = document.createElement('img');
img.src = value;
img.addEventListener('mousedown', (event) => { event.preventDefault(); });
td.innerText = ''; td.appendChild(img);
return td; } } ], colHeaders: true, rowHeights: 55, height: 'auto', autoWrapRow: true, autoWrapCol: true, 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