Skip to content

Pinned Columns Plugin

The Pinned Columns plugin freezes columns to the left or right edge of the grid—essential for keeping key identifiers or action buttons visible while scrolling through wide datasets. Just set pinned: 'left' or pinned: 'right' on your column definitions and the plugin handles the rest.

import '@toolbox-web/grid/features/pinned-columns';

Pin important columns like ID on the left and action buttons on the right. The pinned columns stay fixed while the middle content scrolls horizontally.

import { queryGrid } from '@toolbox-web/grid';
const grid = queryGrid('tbw-grid');
grid.gridConfig = {
columns: [
{ field: 'id', header: 'ID', pinned: 'left', width: 80 },
{ field: 'name', header: 'Name' },
{ field: 'email', header: 'Email' },
{ field: 'department', header: 'Department' },
{ field: 'salary', header: 'Salary', type: 'currency' },
{ field: 'actions', header: 'Actions', pinned: 'right', width: 120 },
],
features: { pinnedColumns: true },
};
ID
Name
Email
Department
Phone
Address
City
Country
Actions

Use the controls below to change which columns are pinned to the left, right, or not pinned. Pinned columns are automatically reordered to the grid edges—left-pinned columns move to the start, right-pinned columns move to the end. Unpinning restores the column to its original position.

The plugin has no configuration options. It is activated when columns have pinned: 'left' or pinned: 'right' set.

See PinnedColumnsPlugin for the full list of methods.

const plugin = grid.getPluginByName('pinnedColumns');
// Get currently pinned columns
const leftPinned = plugin.getLeftPinnedColumns();
const rightPinned = plugin.getRightPinnedColumns();
// Clear all sticky positions
plugin.clearStickyPositions();
// Recalculate offsets (e.g., after column resize)
plugin.refreshStickyOffsets();

For direction-independent pinning, use logical values 'start' and 'end' instead of 'left'/'right':

{ field: 'id', pinned: 'start' } // Left in LTR, Right in RTL
{ field: 'actions', pinned: 'end' } // Right in LTR, Left in RTL

When a column is pinned (either via config or the context menu), the plugin automatically reorders it to the appropriate edge of the grid:

  • pinned: 'left' → moved to the leftmost position (after other left-pinned columns)
  • pinned: 'right' → moved to the rightmost position (before other right-pinned columns)

When a column is unpinned via the context menu, it is restored to its original position in the column order.

This ensures pinned columns are always visible at the grid edges without requiring the user to scroll.

  • Incompatible with Column Groups: Pinned columns cannot be used together with the Column Groups plugin. Pinning reorders columns to the grid edges, but moving a column out of its column group is not supported. When both plugins are loaded, a development-mode warning is shown and the pin/unpin context menu items are hidden.

  • Header-only sticky in virtualized grids: Due to the row virtualization architecture (will-change: transform on the rows container), position: sticky only works on header cells. Data row cells receive the sticky CSS classes but the browser cannot honour them because the transformed ancestor creates a new containing block.

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