Action Column Toggles
Summary
- A
toggleControl is bound to a boolean on the row - Use
fieldfor automatic read/write (likecommandshortcuts) orvalue/onChangefor custom behaviour variantisswitch(default),checkbox, orbutton
A toggle Control is for an immediate on/off action — active / suspended, has wiki, starred, and so on.
The simplest form sets field to the row data property. AdapTable reads the current value and writes changes back for you — the same shortcut idea as command: 'edit'.
Use value and onChange when you need custom logic (async saves, side effects, writing a different property, and so on).
Note
field is the row data property, not the Action Column's columnId. The Action Column is a separate synthetic column (for example wiki_toggle) that displays the control; field: 'has_wiki' is the boolean it reads and writes.
variant is one of:
| Variant | Rendering |
|---|---|
switch | Sliding on/off switch (default) |
checkbox | Compact checkbox |
button | Pressed / 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',
},
],
},
],
},Put the Column in actionColumnOptions.actionColumns.
Supply columnId and an optional friendlyName.
Set type to 'toggle'.
Set field to the boolean property on the row. AdapTable handles read and write.
switch is the default. Use checkbox for a compact control, or button with an icon.
Custom handlers
When you need bespoke behaviour, omit field and supply value and onChange instead.
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,
});
},
},
],
},
],
},Put the Column in actionColumnOptions.actionColumns.
Supply columnId and an optional friendlyName.
Set type to 'toggle'.
value reads the boolean from the row.
onChange receives the new checked state. Use gridApi.setCellValue to write it back.
checkbox suits a labelled control; button works well with an icon.
- Wiki —
switchwithfield: 'has_wiki'; the Has Wiki data column is in the layout so you can see both update together - Pages —
checkboxwith customvalue/onChangeviagridApi.setCellValue(no Has Pages column shown) - Projects —
buttonvariant with afoldericon and custom handlers (no Has Projects column shown)