Skip to main content

Conditionally set colors

Change styles during the rendercell event.

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('rendercell', function (e) {
  if (e.cell.header.name === 'Ei' && /omittam/.test(e.cell.value)) {
    e.ctx.fillStyle = '#AEEDCF';
  }
});

app.append(gridElement);