Colors

Change the text and background color.

You can change the text- and background color of the table.

All provided color strings must be in hex format.

Example #1

Set a text- and background color for the body content.

import { Table } from 'voici.js'

const data = [
  { firstname: 'Homer', lastname: 'Simpson', age: 39 },
  { firstname: 'Marge', lastname: 'Simpson', age: 36 },
  { firstname: 'Bart', lastname: 'Simpson', age: 10 },
  { firstname: 'Lisa', lastname: 'Simpson', age: 8 },
  { firstname: 'Maggie', lastname: 'Simpson', age: 1 }
];

const config = {
  body: {
    bgColor: '#6184D8',
    textColor: '#d8b561'
  }
};

const table = new Table(data, config);
table.print();

Example #2

Set a text- and background color for the header content.

import { Table } from 'voici.js'

const data = [
  { firstname: 'Homer', lastname: 'Simpson', age: 39 },
  { firstname: 'Marge', lastname: 'Simpson', age: 36 },
  { firstname: 'Bart', lastname: 'Simpson', age: 10 },
  { firstname: 'Lisa', lastname: 'Simpson', age: 8 },
  { firstname: 'Maggie', lastname: 'Simpson', age: 1 }
];

const config = {
  header: {
    bgColor: '#6184D8',
    textColor: '#d8b561'
  }
};

const table = new Table(data, config);
table.print();

Example #3

Set a background color columns by column.

import { Table } from 'voici.js'

const data = [
  { firstname: 'Homer', lastname: 'Simpson', age: 39 },
  { firstname: 'Marge', lastname: 'Simpson', age: 36 },
  { firstname: 'Bart', lastname: 'Simpson', age: 10 },
  { firstname: 'Lisa', lastname: 'Simpson', age: 8 },
  { firstname: 'Maggie', lastname: 'Simpson', age: 1 }
];

const config = {
  bgColorColumns: ['#DF3B57', '#0F7173']
};

const table = new Table(data, config);
table.print();

Last updated