Action Column Buttons

View as Markdown

Summary

  • A button Control is a clickable button in an Action Column cell
  • It is the same Adaptable Button used in the Dashboard, Toolbars, Tool Panel and Forms
  • onClick receives ActionColumnContext
  • Optional confirm and async busyLabel cover prompts and pending state

The button Control is the most common Action Column Control.

Note

Up to Version 24 it was the only control available in an Action Column

It is the same Adaptable Button that appears throughout AdapTable — Dashboard buttons, Custom Toolbar buttons, Tool Panel buttons, and Form footer buttons.

The most important property is the onClick function which defines what happens when the button is clicked.

Hint

  • onClick receives ActionColumnContext
  • If the function returns a Promise, the button shows a pending state (optional busyLabel) until it resolves

The other properties are identical to a normal button: label, icon, iconPosition etc.

As with the AdapTable Button they can return or a static value or function that returns a value based on the row.

There is also a style property which is the same as the button's buttonStyle property (with tone & variant).

Note

  • The prop is style because lives on shared BaseControl used by all Action Column Controls, not only buttons
  • The type is still ButtonStyle; handlers receive only the ActionColumnContext (no separate button argument)

There is an optional confirm which shows a prompt before the handler runs.

Developer Guide

Defining a Button Control

actionColumnOptions: {
  actionColumns: [
    {
      columnId: 'update_stars',
      friendlyName: 'Update Stars',
      controls: [
        {
          type: 'button',
          label: (context) =>
            context.data.language === 'JavaScript'
              ? 'Add Star'
              : 'Remove Star',
          style: (context) =>
            context.data.language === 'JavaScript'
              ? {variant: 'raised', tone: 'accent'}
              : {variant: 'raised', tone: 'success'},
          onClick: (context) => {
            const increment =
              context.data.language === 'JavaScript' ? 1 : -1;
            context.adaptableApi.gridApi.setCellValue({
              columnId: 'github_stars',
              newValue: context.data.github_stars + increment,
              primaryKeyValue: context.primaryKeyValue,
              rowNode: context.rowNode,
            });
          },
          hidden: (context) =>
            context.data.name === 'stencil' ||
            context.data.name === 'polymer',
          disabled: (context) =>
            context.data.github_watchers < 200,
        },
      ],
    },
  ],
},
1
Add Action Column Options

Put the Column in actionColumnOptions.actionColumns.

2
Identify the Column

Supply columnId and an optional friendlyName (used as the header caption).

3
Set the Control type

Each item in controls needs a type. For a button this is 'button'.

4
Configure appearance

label and style can be functions of the row — here they change when Language is JavaScript.

5
Handle the click

onClick receives the Action Column context and updates the row.

6
Hide or disable per row

hidden and disabled are also functions of the context.

Action Columns: Button
Fork
  • Update Stars increments or decrements Github Stars
    • label and style change when Language is JavaScript
    • hidden when the Name is stencil or polymer
    • disabled if fewer than 200 Github Watchers
  • TS is an icon-only button that opens the TypeScript site, hidden unless Language is TypeScript
Loading demo…

Multiple Buttons

There is no limit on the number of Buttons (or other Controls) in one Column.

Action Columns: Multiple Buttons
Fork
  • Update Issues has Up and Down buttons that change Issue Change
  • Manage Row is pinned right and uses create / delete Commands instead
Loading demo…