Skip to main content

Allow users to open trees

Allows users to open trees. Use the expandtree event to control the data and settings of the tree grid.

import canvasDatagrid from 'canvas-datagrid';
import createData from '/create-data';

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

app.append(gridElement);

grid.style.height = '300px';
grid.style.width = '100%';
grid.data = createData();

function expandTree(e) {
  e.treeGrid.addEventListener('expandtree', expandTree);
  e.treeGrid.attributes.tree = true;
  e.treeGrid.data = createData();
}
grid.addEventListener('expandtree', expandTree);