Angular Custom Tool Panel

Summary

  • Developers using AdapTable Angular can provide Custom ToolPanels in the Adaptable Tool Panel Component
  • This is done by leveraging AngularFrameworkComponent

AdapTable Angular allows developer to provide custom Tool Panels in an "Angular" way.

These Tool Panels are then added by AdapTable into the AdapTable Tool Panel component .

Developer Guide

Providing a Custom Tool Panel 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 = {
  toolPanelOptions: {
    customToolPanels: [
      {
        name: 'LayoutToggle',
        title: 'Current layout',
        frameworkComponent: {
          type: SlideToggleComponent,
          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 the Tool Panel in Tool Panel Options

Reference the Component created in Step 1 to the customToolPanels collection in Tool Panel Options.

This has 3 properties:

  • name - how it is referenced in AdapTable
  • title - what is shown as the Tool Panel's title
  • frameworkComponent - the Component to be added
initialState: {
  ToolPanel: {
    ToolPanels: [
      {
        Name: 'LayoutToggle',
        VisibilityMode: 'expanded',
      }
      // [...]
    ]
  }
}
3
Set Tool Panel as Expanded (optional)

Optionally we can configure the Tool Panel to display as expanded by default, via Tool Panel State

Angular Components: Custom Tool Panels
Fork
  • In this demo we provide 3 Custom Tool Panels:
    • 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