Action Column Toggles

View as Markdown

Summary

  • A toggle Control is bound to a boolean on the row
  • Use field for automatic read/write (like command shortcuts) or value / onChange for custom behaviour
  • variant is switch (default), checkbox, or button

The toggle Control is for an immediate on/off action, e.g. active / suspended, starred etc.

The simplest form sets field to the row data property.

AdapTable reads the current value and writes changes back for you.

Caution

  • field is the row data property, not the Action Column's columnId.
  • The Action Column is a separate synthetic column
  • e.g. wiki_toggle is the Action Column that displays the control; has_wiki is the boolean field it reads and writes

Variant

The variant property sets the type of toggle and can be one of:

VariantRendering
switchSliding on/off switch (default)
checkboxCompact checkbox
buttonPressed / unpressed toggle button (good with an icon)
Developer Guide

Defining a Toggle Control

actionColumnOptions: {
  actionColumns: [
    {
      columnId: 'wiki_toggle',
      friendlyName: 'Wiki',
      controls: [
        {
          type: 'toggle',
          field: 'has_wiki',
          variant: 'switch',
          tooltip: 'Toggle Has Wiki',
        },
      ],
    },
  ],
},
1
Add Action Column Options

Put the Column in actionColumnOptions.actionColumns.

2
Identify the Column

Supply columnId and an optional friendlyName.

3
Set the Control type

Set type to 'toggle'.

4
Bind to a row field

Set field to the boolean property on the row. AdapTable handles read and write.

5
Choose a variant

switch is the default. Use checkbox for a compact control, or button with an icon.

Custom Logic

Use the value and onChange properties when you need custom logic or behaviour.

For example if you require async saves, side effects, writing a different property etc.

Developer Guide

Defining a Toggle with Custom Handlers

actionColumnOptions: {
  actionColumns: [
    {
      columnId: 'pages_toggle',
      friendlyName: 'Pages',
      controls: [
        {
          type: 'toggle',
          variant: 'checkbox',
          label: 'Pages',
          tooltip: 'Toggle Has Pages',
          value: (context) => Boolean(context.data.has_pages),
          onChange: (checked, context) => {
            context.adaptableApi.gridApi.setCellValue({
              columnId: 'has_pages',
              newValue: checked,
              primaryKeyValue: context.primaryKeyValue,
              rowNode: context.rowNode,
            });
          },
        },
      ],
    },
  ],
},
1
Add Action Column Options

Put the Column in actionColumnOptions.actionColumns.

2
Identify the Column

Supply columnId and an optional friendlyName.

3
Set the Control type

Set type to 'toggle'.

4
Bind the current value

value reads the boolean from the row.

5
Handle the change

onChange receives the new checked state. Use gridApi.setCellValue to write it back.

6
Choose a variant

checkbox suits a labelled control; button works well with an icon.

Action Columns: Toggle
Fork
  • Wiki — switch with field: 'has_wiki'; the Has Wiki data column is in the layout so you can see both update together
  • Pages — checkbox with custom value / onChange via gridApi.setCellValue (no Has Pages column shown)
  • Projects — button variant with a folder icon and custom handlers (no Has Projects column shown)
Loading demo…