Skip to content

VisibilityPlugin

Column Visibility Plugin for tbw-grid

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 { VisibilityPlugin } from '@toolbox-web/grid/plugins/visibility';
OptionTypeDefaultDescription
allowHideAllbooleanfalseAllow hiding all columns (no minimum)
PropertyTypeDefaultDescription
visiblebooleantrueInitial visibility state
meta.lockVisibilitybooleanfalsePrevent user from toggling
MethodSignatureDescription
hideColumn(field: string) => voidHide a column
showColumn(field: string) => voidShow a column
toggleColumn(field: string) => voidToggle visibility
showAllColumns() => voidShow all columns
getHiddenColumns() => string[]Get list of hidden column fields
PropertyDefaultDescription
--tbw-visibility-hovervar(--tbw-color-row-hover)Row hover background
--tbw-panel-padding0.75emPanel content padding
--tbw-panel-gap0.5emGap between items
import { queryGrid } from '@toolbox-web/grid';
import { VisibilityPlugin } from '@toolbox-web/grid/plugins/visibility';
const grid = queryGrid('tbw-grid');
grid.gridConfig = {
columns: [
{ field: 'id', header: 'ID' },
{ field: 'name', header: 'Name' },
{ field: 'phone', header: 'Phone', visible: false }, // Hidden by default
{ field: 'address', header: 'Address', visible: false },
],
plugins: [new VisibilityPlugin()],
};
// Toggle programmatically
const plugin = grid.getPluginByName('visibility');
plugin.showColumn('phone');
import { VisibilityPlugin } from '@toolbox-web/grid/plugins/visibility';
import { ReorderPlugin } from '@toolbox-web/grid/plugins/reorder-columns';
grid.gridConfig = {
plugins: [
new ReorderPlugin(), // Enables drag-drop in visibility panel
new VisibilityPlugin(),
],
};

Extends BaseGridPlugin

Inherited methods like attach(), detach(), afterRender(), etc. are documented in the base class.

PropertyTypeDescription
PANEL_IDcolumnsTool panel ID for shell integration

Show the visibility sidebar panel. Opens the tool panel and ensures this section is expanded.

show(): void

Hide the visibility sidebar panel.

hide(): void

Toggle the visibility sidebar panel section.

toggle(): void

Check if a specific column is visible. Delegates to grid.isColumnVisible().

isColumnVisible(field: string): boolean
NameTypeDescription
fieldstringThe field name to check

boolean - True if the column is visible


Set visibility for a specific column. Delegates to grid.setColumnVisible().

setColumnVisible(field: string, visible: boolean): void
NameTypeDescription
fieldstringThe field name of the column
visiblebooleanWhether the column should be visible

Get list of all visible column fields.

getVisibleColumns(): string[]

string[] - Array of visible field names


Get list of all hidden column fields.

getHiddenColumns(): string[]

string[] - Array of hidden field names


Show all columns. Delegates to grid.showAllColumns().

showAll(): void

Toggle visibility for a specific column. Delegates to grid.toggleColumnVisibility().

toggleColumn(field: string): void
NameTypeDescription
fieldstringThe field name of the column

Show a specific column. Delegates to grid.setColumnVisible().

showColumn(field: string): void
NameTypeDescription
fieldstringThe field name of the column to show

Hide a specific column. Delegates to grid.setColumnVisible().

hideColumn(field: string): void
NameTypeDescription
fieldstringThe field name of the column to hide

Get all columns with their visibility status. Useful for building visibility UI.

getAllColumns(): object[]

object[] - Array of column info with visibility status


Check if the sidebar panel is currently open.

isPanelVisible(): boolean

boolean - True if the panel section is expanded


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