Custom Tool Panels
Summary
- Custom Tool Panels are Tool Panels provided by Developers
- They are provided in Tool Panel Options
- They are hosted in the Adaptable Tool Panel Component
Developers are able to provide custom ToolPanels containing bespoke elements.
They are rendered inside the Adaptable ToolPanel Component alongside the Module ToolPanels.
Note
Once defined, Custom ToolPanels can be configured and used in the same way as Module ToolPanels
Wiring Up Custom Tool Panels
Custom Tool Panels are provided in a 2-step process:
- The Custom Tool Panel is defined in
customToolPanelsin Tool Panel Options - The Custom Tool Panel is referenced in Tool Panel Initial State
Developer Guide
Wiring up a Custom Tool Panel
These are the 2 steps required to provide a Custom Tool Panel in AdapTable.
const adaptableOptions: AdaptableOptions = {
toolPanelOptions: {
customToolPanels: [
{
name: 'buttonCustomToolPanel',
title: 'Quick Actions',
buttons: [
// Adaptable Buttons here
],
},
{
name: 'bespokeContentCustomToolPanel',
title: 'Custom Content',
frameworkComponent: () => {
// bespoke content; use render if AdapTable Vanilla
},
},
],
},
};Create the Custom Tool Panel in customToolPanels in Tool Panel Options.
- Add
name— how the Tool Panel is internally referenced in AdapTable - Optionally add
title— the label shown in the Tool Panel header - Add the content (either AdapTable Buttons or bespoke rendering)
initialState: {
ToolPanel: {
ToolPanels: [
{
Name: 'buttonCustomToolPanel',
VisibilityMode: 'expanded',
},
{
Name: 'bespokeContentCustomToolPanel',
VisibilityMode: 'collapsed',
},
];
}
}Reference the Custom Tool Panel in Tool Panel Initial State.
Use the name supplied in Tool Panel Options.
Optionally configure the Tool Panel to display as expanded or collapsed.
Custom Tool Panel Contents
Custom Tool Panels can contain 2 different sets of content:
- Buttons — an array of Adaptable Buttons
- Bespoke content — for when more than buttons are required
Deep Dive
Anatomy of a Custom ToolPanel
Providing AdapTable Buttons
Provide an array of Adaptable Buttons on the buttons property of CustomToolPanel.
This workflow is framework-agnostic — the same buttons configuration works for AdapTable Vanilla, React, Angular, and Vue.
Hint
If you only need a few actions in the Tool Panel, prefer buttons over bespoke render / frameworkComponent content
Developer Guide
Providing Custom Tool Panel Buttons
Deep Dive
Configuring Custom Tool Panel Buttons
- This example defines one Custom Tool Panel —
Quick Actions— containing three AdapTable Buttons:- Switch Theme — toggles light / dark theme
- Open Named Queries — opens the Named Query settings panel
- Show Date — displays today's date in an alert
- The AdapTable Tool Panel opens on load so the Custom Tool Panel is visible
Providing Bespoke Content
When Adaptable Buttons are not enough, you can provide bespoke HTML in a Custom Tool Panel.
This is done using the render property — a function that returns an HTML string (or null).
render?: (context: CustomRenderContext) => string | null;The function receives CustomRenderContext defined as follows:
| Property | Type | Description |
|---|---|---|
| element | HTMLDivElement | Container Div Element |
| phase | 'onMount' | 'onDestroy' | Phase of DOM Element lifecycle |
| adaptableContext | any | Custom application Context provided in AdaptableOptions.adaptableContext |
Note
- On
onMount, return markup for AdapTable to inject into the panel container (context.element) - On
onDestroy, returnnulland run any teardown (for example removing listeners attached tocontext.element)
Developer Guide
Providing Bespoke Tool Panel Content
- Two Custom Tool Panels use
renderonly (nobuttons):- Hello World — static HTML returned from
render - Application — an input rendered on
onMountusingCustomRenderContextlifecycle
- Hello World — static HTML returned from
- The AdapTable Tool Panel opens on load
Caution
- Unlike Dashboard Toolbars, the close button on a Tool Panel is always visible (and not configurable)
- Module Tool Panels always display the Configure button; Custom Tool Panels do not
AdapTable Resources
- Adaptable Buttons
- Building Custom Components
- Custom Toolbars — similar pattern for providing bespoke content