Vue 2 Data GridCustom renderer in Vue 2

Create a custom cell renderer, and use it in your Vue 2 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.

Example - Declaring a renderer as a function

The following example is an implementation of @handsontable/vue with a custom renderer added. It takes an image URL as the input and renders the image in the edited cell.

import { HotTable } from '@handsontable/vue';
import { registerAllModules } from 'handsontable/registry';
import 'handsontable/dist/handsontable.full.css';

// register Handsontable's modules
registerAllModules();

const ExampleComponent = {
  data() {
    return {
      hotSettings: {
        data:
          [
            ['A1', 'https://handsontable.com/docs/14.6/img/examples/professional-javascript-developers-nicholas-zakas.jpg'],
            ['A2', 'https://handsontable.com/docs/14.6/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;

There is a newer version of Handsontable available. Switch to the latest version ⟶