Summary

  • Developers using AdapTable Angular can provide Custom Toolbars in the Dashboard
  • This is done by leveraging AngularFrameworkComponent

This page explains how to create Custom Toolbars with bespoke content while using AdapTable Angular.

Hint

Developer Guide

Providing a Custom Toolbar in AdapTable Angular

@Component({
  selector: 'slide-toggle',
  template: `
    <label class="switch">
      <input
        class="switch-input"
        type="checkbox"
        [checked]="active"
        (change)="onToggle()" />
      <span
        class="switch-label"
        [attr.data-on]="onText"
        [attr.data-off]="offText"
        [style.background]="active ? onColor : offColor"></span>
      <span class="switch-handle"></span>
    </label>
  `,
  styles: [
    `
      // [...]
    `,
  ],
})
export class SlideToggleComponent {
  active = false;

  onText = 'ON';
  onColor = 'var(--ab-color-success)';

  offText = 'OFF';
  offColor = 'var(--ab-color-info)';

  constructor(@Inject(ADAPTABLE_API) private adaptableApi: AdaptableApi) {}

  onToggle() {
    this.active = !this.active;
    this.onChange(this.active);
  }

  onChange(toggleValue: boolean) {
    // overwritten in onSetup()
  }
}
1
Define the Template Component

In this example we are providing a SlideToggle button, which is a standard Angular Component.

The implementation that we provide is entirely generic and reusable, as the I/O params are set via the onSetup() function in the frameworkComponent.

const adaptableOptions: AdaptableOptions = {
  dashboardOptions: {
    customToolbars: [
      {
        name: 'LayoutToggle',
        title: 'Current layout',
        frameworkComponent: {
          type: SlideToggleComponent,
          // configure custom content & behaviour
          onSetup: ({adaptableApi}): Partial<SlideToggleComponent> => {
            return {
              onText: 'Pivot',
              offText: 'Standard',
              onChange: toggleValue => {
                if (toggleValue) {
                  adaptableApi.layoutApi.setLayout('Pivot Cols Layout');
                } else {
                  adaptableApi.layoutApi.setLayout('Standard Layout');
                }
              },
            };
          },
        },
      },
      // [...]
   ],
  }
}
2
Reference and Create Custom Toolbar in Dashboard Options

Import the Component and create a Custom Toolbar definition.

In the definition do 2 things:

  1. reference the Component in the type property (of frameworkComponent)

  2. provide custom implementation of Component via the onSetup() function

initialState: {
  Dashboard: {
    Tabs: [ 
      { 
        Name: 'Demo', Toolbars: ['LayoutToggle'] 
      } 
    ]
  }
}
3
Reference Toolbar in Initial Adaptable State

Reference the Custom Toolbar in AdapTable's Dashboard.

Use the value supplied as the name property in Dashboard Options:

You can set the Custom Toolbar as:

Angular Components: Custom Toolbars
Fork
  • In this demo we provide 3 Custom Toolbars:
    • a SlideToggle button switching between standard and pivot layout
    • a CustomQuickSearch toolbar which is disabled when in pivot mode
    • a SlideToggle button enabling/disabling the gradient style for the GitHub Stars column
  • The Layout toggle and Gradient Style toggle re-use the same toggle component but with different configurations.

Expand to see more