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
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
fieldis the row data property, not the Action Column'scolumnId.- The Action Column is a separate synthetic column
- e.g.
wiki_toggleis the Action Column that displays the control;has_wikiis the boolean field it reads and writes
Variant
The variant property sets the type of toggle and can be 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 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,
});
},
},
],
},
],
},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)