Skip to main content

Enable and Disable Columns

Enable

Optional param. Pass the names of columns as a list. Use it when your JSON data contains extra fields and you want only a few columns to be visible.

import { Table } from 'console-table-printer';

const p = new Table({
enabledColumns: ["id", "text"],
});

// add rows with color
p.addRows([
{
id: 2,
text: "This row is some shit",
garbages: 10.212,
},
{
id: 3,
text: "I would like some more text",
garbages: 10.212,
},
{
id: 4,
text: "I would like some text",
garbages: "some garbase shit that I dont want to see",
},
]);

p.printTable();
Screenshot

Disable

This one is good in case you have a short list of disabled columns.

import { Table } from 'console-table-printer';

const p = new Table({
disabledColumns: ["garbages"],
});

// add rows with color
p.addRows([
{
good_text: "This row is some shit",
id: "1",
garbages: 10.212,
},
{
id: "2",
good_text: "I would like some more text",
garbages: 10.212,
},
{
id: "3",
good_text: "I would like some text",
garbages: "some garbase shit that I dont want to see",
},
]);

p.printTable();
Screenshot