Skip to main content

Simple context menu

NB: This example seems to be broken, calling selectArea is not selecting cells.

Add your own items to the context menu.

import canvasDatagrid from 'canvas-datagrid';
import data from '/data.json';

const app = document.getElementById('app');
const gridElement = document.createElement('div');
const grid = canvasDatagrid({
  parentNode: gridElement,
  data,
});

grid.addEventListener('contextmenu', function (e) {
  e.items.push({
    title: 'Select all',
    click: function (ev) {
      grid.selectArea({
        top: 0,
        bottom: 2,
        left: 0,
        right: 2,
      });
      grid.draw();
    },
  });
});

app.append(gridElement);