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. When Column Grouping is also active, the panel shows columns in their actual display order, and fragmented groups (split across non-contiguous positions) appear as separate panel sections. Group headers in the panel are draggable and move only the columns in that fragment.

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 and locked columns. Click the column visibility icon in the header to open the panel.

Column search
Layout
Initially hiddenColumns hidden by default
Locked (non-toggleable)Columns that cannot be hidden

See VisibilityConfig for the full list of options and defaults.

Column search is most useful for grids with many columns. For wide grids, we also recommend Column Virtualization: search helps users find columns in the panel, while virtualization reduces the number of columns rendered in the grid. Virtualization requires fitMode: 'fixed'; see its layout requirements.

Set searchable: true to add a search input above the column list. Search is disabled by default. Enable Column search in the demo above to try it in sidebar or dropdown mode.

import '@toolbox-web/grid/features/shell';
import '@toolbox-web/grid/features/visibility';
grid.gridConfig = {
features: { shell: true, visibility: { searchable: true } },
};

The same configuration works through gridConfig in React, Vue, and Angular. For direct plugin registration, use new VisibilityPlugin({ searchable: true }). Prefer feature config for automatic dependency resolution; use direct registration when managing plugin instances yourself. See features and plugins.

Search uses a trimmed, case-insensitive substring of the displayed name (header || field). Hidden columns are searchable; utility columns are excluded. Typing does not change grid data, column visibility, or column order. Clear the query to restore the full list.

While searching:

  • Group checkboxes affect only matching columns in the displayed fragment, respecting locked columns.
  • Empty groups disappear, but separate fragments are not merged or reordered.
  • Show All still shows every column, including nonmatches, and keeps the query.
  • Panel drag handles and move menus are unavailable until the query is cleared.

The query survives panel close/reopen and column updates on the same plugin instance. It is transient UI state, not part of saved column state. A new plugin instance starts empty.

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-searchOpt-in search input
.tbw-visibility-search-statusPolite empty-result status
.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-row--groupedColumn row inside a group section
.tbw-visibility-group-headerGroup header row (with checkbox)
.tbw-visibility-group-header.reorderableDraggable group header
.tbw-visibility-handleDrag handle element
.tbw-visibility-labelCheckbox + text wrapper
.tbw-visibility-move-menuClick-only move menu (SC 2.5.7)
.tbw-visibility-move-menu-itemAn entry in that menu

Opt-in search has an accessible name (SC 4.1.2 Name, Role, Value) and retains native text editing. A polite status region announces No matching columns without moving focus (SC 4.1.3 Status Messages). The input stays mounted while results update. Escape closes overlay/dropdown panels; persistent push sidebars stay open. Translate the UI with columns.searchLabel, columns.searchPlaceholder, and columns.noMatchingColumns in gridConfig.locale.

Reordering from the panel is drag-and-drop, which WCAG 2.2 SC 2.5.7 Dragging Movements requires a single-pointer alternative for. Clicking a drag handle — instead of dragging it — opens a menu with Move up, Move down, Move to top and Move to bottom. Entries that would be a no-op, or that would land on a column the grid refuses to move, are disabled.

Both handle kinds are covered:

  • A column row handle moves that one column.
  • A group header handle moves the whole fragment as a block, exactly as dragging it would.

The handles stay draggable, so nothing changes for mouse users: a press-and-release without movement never starts a drag, so the click and the drag never conflict. See the accessibility guide for every drag surface and its alternative.