Vue 2 Data GridCustom editor in Vue 2

Create a custom cell editor, and use it in your Vue 2 data grid by declaring it as a class.

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.

Example - Declaring an editor as a class

The following example implements the @handsontable/vue component with a custom editor added, utilizing the placeholder attribute in the editor's input element.

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

// 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 = {
  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;

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