Core Features

Advanced Features

Vue Data GridColumns Tool Panel - Customisation

Version 36.3.0
Enterprise

Customise how columns appear in the Columns Tool Panel: their styling and names, custom label renderers, expanding and collapsing column groups, the context menu and the drag image.

Styling Columns Copy Link

The example below styles the gold, silver and bronze columns using toolPanelClass.

To add a CSS class to a column in the tool panel, set toolPanelClass on its column definition:

<ag-grid-vue
    :columnDefs="columnDefs"
    /* other grid options ... */>
</ag-grid-vue>

this.columnDefs = [
    // set as string
    { field: 'gold', toolPanelClass: 'tp-gold' },

    // set as array of strings
    { field: 'silver', toolPanelClass: ['tp-silver'] },

    // set as function returning string or array of strings
    {
        field: 'bronze',
        toolPanelClass: params => {
            return 'tp-bronze';
        },
    }
];

Naming Columns Copy Link

To give a column a different name in the tool panel, use a headerValueGetter and return the name when params.location is 'columnToolPanel':

<ag-grid-vue
    :columnDefs="columnDefs"
    /* other grid options ... */>
</ag-grid-vue>

this.columnDefs = [
    {
        field: 'country',
        headerValueGetter: params => params.location === 'columnToolPanel' ? 'Country (TP)' : 'Country',
    }
];

In the example above, the country column uses a headerValueGetter to show a different name in the tool panel, the drop zones and the grid header. Drag it into the Row Groups section to see the drop zone name.

Custom Label Renderers Copy Link

Use columnLabelRenderer to replace the text shown for columns and column groups in the Columns section. The grid continues to provide and manage the checkbox, drag handle and group expand controls.

Supply the renderer directly, or reference a name registered in the grid's components map, and pass additional properties through columnLabelRendererParams. To use different renderers for different columns or column groups, use columnLabelRendererSelector instead.

<ag-grid-vue
    :components="components"
    :sideBar="sideBar"
    /* other grid options ... */>
</ag-grid-vue>

this.components = {
    customColumnLabel: CustomColumnLabel,
};
this.sideBar = {
    toolPanels: [{
        id: 'columns',
        labelDefault: 'Columns',
        labelKey: 'columns',
        iconKey: 'columns',
        toolPanel: 'agColumnsToolPanel',
        toolPanelParams: {
            columnLabelRenderer: 'customColumnLabel',
            columnLabelRendererParams: {
                columnIcon: '●',
                columnGroupIcon: '◆',
            },
        },
    }],
};

The renderer receives either column or columnGroup, together with the resolved displayName and a source of 'columnsToolPanel'. The same renderer can be configured independently for the Column Chooser.

Column search, tooltips, drag labels and accessibility announcements continue to use displayName, rather than text extracted from the renderer. Column selection rows have a fixed height, so renderer content should remain inline and fit within the configured list item height. Clicking the rendered label retains the normal selection behaviour; interactive elements should stop event propagation when they should not toggle the column.

Expand / Collapse Column Groups Copy Link

Call expandColumnGroups() and collapseColumnGroups() on the Columns Tool Panel instance to expand or collapse all of its column groups, or pass groupIds to target individual groups; see Expand / Collapse API. To start with all column groups collapsed, set contractColumnSelection in toolPanelParams instead.

contractColumnSelectionCopy Link
boolean
By default, column groups start expanded. Pass true to start with groups collapsed.

In the example below, onGridReady collapses all column groups in the tool panel. Use the buttons to try each call from the Expand / Collapse API.

The expanded column groups are saved and restored as part of Grid State.

Context Menu Copy Link

Right-clicking or long-pressing a column or column group label opens a menu with items for moving, grouping, aggregating and pivoting. The menu can be customised, including with custom menu items.

Built-In Menu Items Copy Link

The following menu items are shown by default based on the column's configuration and the grid's current state:

  • scrollIntoView: "Scroll column into View". Scrolls the column into view. Hidden while pivoting, or when the column is pinned or hidden.
  • rowGroup: "Group by column" or "Un-Group by column". Appears only when the column allows row grouping.
  • value: "Add column to values" or "Remove column from values". Adds or removes the column as an aggregated value (the Values section). Appears only when the column allows aggregation.
  • pivot: "Add column to labels" or "Remove column from labels". Adds or removes the column as a pivot column label (the Column Labels section). Appears only in pivot mode when the column allows pivoting.
  • moveUp: "Move Up". Moves the column or group one available position up the list.
  • moveDown: "Move Down". Moves the column or group one available position down the list.

For a column group, rowGroup, value and pivot apply to every child column that individually allows the action; scrollIntoView scrolls only the first visible child column into view.

The move items also appear in the Column Chooser. They are hidden in pivot mode but are unaffected by functionsReadOnly.

Movement follows Column Moving and tool panel reordering restrictions. In deferred mode, changes wait for Apply.

Customise labels using the moveUp / moveDown locale keys and arrows using the menuMoveUp / menuMoveDown icon keys.

With Read Only Functions, rowGroup, value and pivot are not shown.

Custom Menu Items Copy Link

Customise the menu items with colDef.columnMenuItems or getColumnMenuItems(). See Column Menu - Customising the menu items. The callback's params.source is 'columnsToolPanel' when triggered from the Columns Tool Panel.

The example below shows both the built-in items and this customisation. Note the following:

  • Right-click Gold to see the built-in items plus an optional pinning sub-menu and a custom Highlight Column item, added by the getColumnMenuItems() callback.
  • Silver hides the "Scroll Silver into View" item via a colDef.columnMenuItems callback. As colDef.columnMenuItems takes priority over getColumnMenuItems(), Silver doesn't get the Highlight Column item.
  • Bronze restricts its menu to only "Add Bronze to values" via a static colDef.columnMenuItems array, so it doesn't get the Highlight Column item either.
  • colDef.columnMenuItems applies to every column menu, so the Silver and Bronze changes also apply to their column header menu and Column Chooser menu. Other columns keep their defaults in those menus, as getColumnMenuItems() returns params.defaultItems for those sources.

Drop Zone Menus Copy Link

Move Up and Move Down reorder pills within Row Groups, Values and Column Labels, not grid columns. Horizontal panels use Move Left and Move Right.

Right-click a pill to open its menu. With a pill focused, ⇧ Shift+F10 or the context-menu key opens the same menu.

Move items follow drag-and-drop eligibility and group locking. They are hidden with functionsReadOnly, but pivot mode and column-layout restrictions do not block them.

Labels use the moveUp, moveDown, moveLeft, moveRight locale keys; arrows use the menuMoveUp, menuMoveDown, menuMoveLeft, menuMoveRight icon keys.

Use getColumnDropZoneMenuItems to filter defaultItems, add custom items or return [] to hide a menu. Its source is 'rowGroup', 'pivot' or 'aggregation'. For example, hide the Values menu and keep the others:

const gridOptions = {
    getColumnDropZoneMenuItems: ({ source, defaultItems }) =>
        source === 'aggregation' ? [] : defaultItems,
};

Keep the callback free of side effects; it may run before the menu opens. Column-menu callbacks do not configure drop-zone menus.

getColumnDropZoneMenuItemsCopy Link
GetColumnDropZoneMenuItems
Customise the context menu for pills in Row Group, Pivot and Values drop zones. Return [] to hide it. Called when pills are created to determine menu availability for accessibility, and when opening a menu. Independent of columnMenuItems and getColumnMenuItems.

Custom Drag and Drop Image Copy Link

The drag and drop image can be customised via the grid properties dragAndDropImageComponent and dragAndDropImageComponentParams.

Any valid Vue component can be a drag and drop image component, however it must implement the IDragAndDropImage interface:

IDragAndDropImage Copy Link


interface IDragAndDropImage {
  setIcon(iconName: string | null, shake: boolean): void;

  setLabel(label: string): void;

}

Custom Params Copy Link

On top of the parameters provided by the grid, you can also provide your own parameters. This is useful if you want to allow configuring the component. For example, you might have parts of the grid that you want to highlight with a different colour. The example above passes its own parameters through dragAndDropImageComponentParams.

const gridOptions = {
    dragAndDropImageComponent: 'MyDragAndDropImageComponent',
    dragAndDropImageComponentParams : {
        accentColour: 'SlateGray'
    }
}

API Copy Link

Custom Label Renderer Parameters Copy Link

columnLabelRendererCopy Link
any
Component used to render column and column group labels. The checkbox, drag handle and expand controls remain grid managed.
columnLabelRendererParamsCopy Link
any
Additional parameters passed to the columnLabelRenderer.
columnLabelRendererSelectorCopy Link
ColumnSelectionLabelRendererSelectorFunc
Callback to select which renderer to use for an individual column or column group label. The result can also provide renderer-specific params. Return undefined to use columnLabelRenderer.

The parameters passed to a custom label renderer:

Properties available on the IColumnSelectionLabelRendererParams<TData = any, TContext = any> interface.

displayNameCopy Link
string | null
The text value resolved from the column or column group definition.
The column being rendered, or null when rendering a column group.
The column group being rendered, or null when rendering a column.
sourceCopy Link
ColumnSelectionPanelSource
The panel in which the label is rendered.
The grid api.
Application context as set on gridOptions.context.

Expand / Collapse API Copy Link

const columnsToolPanel = this.gridApi.getToolPanelInstance('columns');

// expands all column groups in the Columns Tool Panel
columnsToolPanel.expandColumnGroups();

// collapses all column groups in the Columns Tool Panel
columnsToolPanel.collapseColumnGroups();

// expands the 'Athlete' and 'Competition' column groups in the Columns Tool Panel
columnsToolPanel.expandColumnGroups(['athleteGroupId', 'competitionGroupId']);

// collapses the 'Competition' column group in the Columns Tool Panel
columnsToolPanel.collapseColumnGroups(['competitionGroupId']);
expandColumnGroupsCopy Link
Function
Expands the column groups with the supplied groupIds, or all column groups if not supplied.
collapseColumnGroupsCopy Link
Function
Collapses the column groups with the supplied groupIds, or all column groups if not supplied.