Skip to content

Column Visibility Plugin

The Visibility plugin gives users control over which columns are displayed. Hide less important columns by default, let users toggle them via a column chooser UI, or programmatically show/hide columns based on user preferences or screen size.

💡 Optional Enhancement: When ReorderPlugin is also loaded, columns in the visibility panel become draggable for reordering.

import '@toolbox-web/grid/features/visibility';

Set hidden: true on columns you want hidden by default. The feature provides a UI and API for toggling column visibility at runtime.

import { queryGrid } from '@toolbox-web/grid';
const grid = queryGrid('tbw-grid');
grid.gridConfig = {
columns: [
{ field: 'id', header: 'ID' },
{ field: 'name', header: 'Name' },
{ field: 'email', header: 'Email' },
{ field: 'phone', header: 'Phone', hidden: true }, // Hidden by default
{ field: 'address', header: 'Address', hidden: true },
],
features: { visibility: true },
};
// Toggle visibility programmatically
const plugin = grid.getPluginByName('visibility');
plugin.showColumn('phone');
plugin.hideColumn('email');

Toggle the controls to explore hidden columns, locked columns, and the allowHideAll option. Click the column visibility icon in the header to open the panel.

Allow hide all Allow hiding every column
Initially hidden Columns hidden by default
Locked (non-toggleable) Columns that cannot be hidden

See VisibilityConfig for the full list of options and defaults.

const plugin = grid.getPluginByName('visibility');
// Panel control
plugin.show(); // Open the visibility panel
plugin.hide(); // Close the panel
plugin.toggle(); // Toggle panel open/closed
const open = plugin.isPanelVisible(); // Check if panel is open
// Column visibility
plugin.hideColumn('email');
plugin.showColumn('email');
plugin.toggleColumn('email');
plugin.showAll(); // Show all hidden columns
plugin.setColumnVisible('email', false); // Set visibility directly
const isVis = plugin.isColumnVisible('email');
// Query state
const hidden = plugin.getHiddenColumns(); // List of hidden field names
const visible = plugin.getVisibleColumns(); // List of visible field names
const all = plugin.getAllColumns(); // Full column metadata with visibility

The visibility panel supports CSS custom properties for theming. Override these on tbw-grid or a parent container:

PropertyDefaultDescription
--tbw-visibility-hovervar(--tbw-color-row-hover)Row hover background
--tbw-panel-paddingvar(--tbw-spacing-md, 0.5rem)Panel content padding
--tbw-panel-gapvar(--tbw-spacing-md, 0.5rem)Gap between items
--tbw-menu-item-padding0.375rem 0.25remRow padding
--tbw-font-size-sm0.8125remLabel font size
--tbw-font-size-2xs0.625remDrag handle size
--tbw-color-fg-muted#888Muted text (locked items)
--tbw-border-radius0.25emRow border radius
tbw-grid {
/* Custom visibility panel styling */
--tbw-visibility-hover: #e8f4fd;
--tbw-panel-padding: 1rem;
--tbw-panel-gap: 0.75rem;
}

The visibility panel uses these class names for advanced customization:

ClassElement
.tbw-visibility-contentPanel container
.tbw-visibility-listScrollable column list
.tbw-visibility-rowIndividual column row
.tbw-visibility-row.lockedNon-toggleable column
.tbw-visibility-row.reorderableCan be dragged (with ReorderPlugin)
.tbw-visibility-row.draggingCurrently being dragged
.tbw-visibility-handleDrag handle element
.tbw-visibility-labelCheckbox + text wrapper
AI assistants: For complete API documentation, implementation guides, and code examples for this library, see https://raw.githubusercontent.com/OysteinAmundsen/toolbox/main/llms-full.txt