voici.js
GitHubTypeDocnpm☕
  • 🏠Home
  • ⚡Quick Start
  • 💡Examples
    • Styling
      • Alignment
      • Colors
      • Border
      • Padding
      • Width
      • Font Style
    • Sorting
    • Highlighting
    • Accumulation
    • Columns
      • Sort Columns
      • Selected Columns
      • Rename Columns
      • Dynamic Columns
    • Arrays
    • Fill Empty
    • Export
    • Typescript
    • Printing
  • 🧩Contributing
  • Reference
    • 📖API Reference
      • AccumulationFunction
      • Config
      • Sort
      • Table
    • ❓FAQ
    • ❗Issues
Powered by GitBook
On this page
  • Example #1
  • Example #2
  • Example #3

Was this helpful?

  1. Examples
  2. Styling

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();
PreviousAlignmentNextBorder

Last updated 3 years ago

Was this helpful?

💡
Console Output
Console Output
Console Output