Angular UI Components Documentation

Angular DockPanel Component

The DockPanel component for Angular represents a container for other widgets or elements. It arranges its inner elements depending on the value of the 'dock' attribute. The possible 'dock' attribute values are: 'left, right, top and bottom'.

Prerequisites

Refer to Angular Getting Started before you start with this help topic.

Configuration

I. Imports

The DockPanel component for Angular requires the following imports.

import{ jqxDockPanelComponent } from 'jqwidgets-ng/jqxdockpanel';           

II. @Component Decorator

A class is marked as an Angular component through the @Component decorator:

@Component({
selector: 'app-root',
template: `
<jqxDockPanel [height]='height' #DockPanel1>
<div id='first' dock='left' style='background: #486974;'>
First Div
</div>
<div id='second' dock='top' style='height: 100px; background: #368ba7;'>
Second Div
</div>
<div id='third' dock='right' style='background: #df7169;'>
Third Div
</div>
<div id='fourth' style='background: #a73654;'>
Fourth Div
</div>
</jqxDockPanel>`
})

  • selector - CSS selector that identifies this component in a template
  • styles - inline-defined styles to be applied to this component's view
  • styleUrls - list of URLs to stylesheets to be applied to this component's view
  • template - inline-defined template for the view
  • templateUrl - URL to an external file containing a template for the view
The full list of @Component decorator properties is available on: Angular @Component Decorator API


Every jQWidgets Angular component has an [auto-create] attribute which determines whether the component is automatically created or is created on demand by API method call.
By default, the [auto-create] attribute value is true.

III. Create the AppComponent class

export class AppComponent
{
height: number = 300;
}

The AppComponent class is used to instantiate the app. In some of the examples, we use @ViewChild and ngAfterViewInit.

  • @ViewChild: makes a reference using a DockPanel selector. View queries are set before the ngAfterViewInit callback is called.
    @ViewChild('dockPanelReference') myDockPanel: jqxDockPanelComponent;
  • ngAfterViewInit - this is an Angular Component Lifecycle method in which we create our angular components. After the view is initialized, myDockPanel is available.
    For more information about this methods please refer to Angular Component Lifecycle API

The following example demonstrates the DockPanel component for Angular.

app.component.htm

<div style="width: 300px; height: 600px; font-size: 13px; font-family: Verdana;">
<jqxDockPanel #jqxDockPanel
[width]="300"
[height]="210">
<div #first dock='left' style='background: #486974;'>
First Div
</div>
<div #second dock='top' style='height: 100px; background: #368ba7;'>
Second Div
</div>
<div #third dock='right' style='background: #df7169;'>
Third Div
</div>
<div #fourth style='background: #a73654;'>
Fourth Div
</div>
</jqxDockPanel>
<br />
<div>Layout Types:</div>
<div id='layout'>
<img title='click to apply a new layout' alt='layout types' src='../images/LayoutTypes.png' />
</div>
<br />
<div>Spiral:</div>
<jqxDockPanel #jqxDockPanel2
[width]="300"
[height]="210"
[lastchildfill]="false">
<div #Div1 dock='left' style='background: #486974; width: 20px;'>
1
</div>
<div #Div2 dock='top' style='background: #368ba7; height: 20px;'>
2
</div>
<div #Div3 dock='right' style='background: #df7169; width: 20px;'>
3
</div>
<div #Div4 dock='bottom' style='background: #a73654; height: 20px;'>
4
</div>
</jqxDockPanel>
</div>

app.component.ts

import { Component, ViewChild, AfterViewInit, ElementRef } from '@angular/core';
import { jqxDockPanelComponent } from 'jqwidgets-ng/jqxdockpanel';
@Component({
selector: 'app-root',
templateUrl: './app.component.html'
})
export class AppComponent implements AfterViewInit {
@ViewChild('jqxDockPanel') DockPanel: jqxDockPanelComponent;
@ViewChild('jqxDockPanel2') DockPanel2: jqxDockPanelComponent;
@ViewChild('first') firstElement: ElementRef;
@ViewChild('second') secondElement: ElementRef;
@ViewChild('third') thirdElement: ElementRef;
@ViewChild('fourth') fourthElement: ElementRef;
ngAfterViewInit() {
document.getElementById('layout').addEventListener('click', (event) => {
layoutOnClick(event);
this.DockPanel.refresh();
}, true);
this.DockPanel.elementRef.nativeElement.style.color = 'white';
this.DockPanel2.elementRef.nativeElement.style.color = 'white';
let layoutOnClick = (event) => {
let layoutsLength = 4;
let firstElement = this.firstElement.nativeElement;
let secondElement = this.secondElement.nativeElement;
let thirdElement = this.thirdElement.nativeElement;
let fourthElement = this.fourthElement.nativeElement;
let position = parseInt(event.clientX) - parseInt(event.target.offsetLeft);
if (position < 55) {
firstElement.setAttribute('dock', 'bottom');
firstElement.style.height = '105px';
secondElement.setAttribute('dock', 'left');
secondElement.style.width = '100px';
thirdElement.setAttribute('dock', 'left');
thirdElement.style.width = '100px';
fourthElement.setAttribute('dock', 'left');
fourthElement.style.width = '100px';
} else
if (position < 115) {
for (let i = 0; i < layoutsLength; i++) {
this.DockPanel.elementRef.nativeElement.firstChild.firstChild.children[i].style.width = '100px';
}
firstElement.setAttribute('dock', 'left');
secondElement.setAttribute('dock', 'right');
thirdElement.setAttribute('dock', 'bottom');
thirdElement.style.height = '140px';
fourthElement.setAttribute('dock', 'top');
fourthElement.style.height = '70px';
} else if (position < 175) {
for (let i = 0; i < layoutsLength; i++) {
this.DockPanel.elementRef.nativeElement.firstChild.firstChild.children[i].style.width = '150px';
}
firstElement.setAttribute('dock', 'left');
secondElement.setAttribute('dock', 'left');
thirdElement.setAttribute('dock', 'left');
fourthElement.setAttribute('dock', 'left');
} else if (position < 235) {
for (let i = 0; i < layoutsLength; i++) {
this.DockPanel.elementRef.nativeElement.firstChild.firstChild.children[i].style.height = '70px';
}
firstElement.setAttribute('dock', 'top');
secondElement.setAttribute('dock', 'top');
thirdElement.setAttribute('dock', 'top');
fourthElement.setAttribute('dock', 'top');
}
else {
for (let i = 0; i < layoutsLength; i++) {
this.DockPanel.elementRef.nativeElement.firstChild.firstChild.children[i].style.width = '100px';
}
firstElement.setAttribute('dock', 'left');
secondElement.setAttribute('dock', 'left');
thirdElement.setAttribute('dock', 'left');
fourthElement.setAttribute('dock', 'left');
}
}
}
}

Run Code

IV. Create DockPanel component with JSON

  • Add the imports.

    import { Component, ViewChild, AfterViewInit } from '@angular/core';
    import { jqxDockPanelComponent } from 'jqwidgets-ng/jqxdockpanel';

    @Component decorator:

    @Component({
        selector: 'app-root',
        template: `<jqxDockPanel #dockPanelReference></jqxDockPanel>`
    })
    
  • Create the AppComponent class.

    • @ViewChild: makes a reference using a DockPanel selector. View queries are set before the ngAfterViewInit callback is called.
      @ViewChild('dockPanelReference') myDockPanel: jqxDockPanelComponent;
    • ngAfterViewInit: All Angular components have an integrated method called createComponent that accept a JSON object with the component initialization properties. If no argument is passed, default properties will be used. If you would like to dynamically set properties after creation, you can use the setOptions method.
      ngAfterViewInit(): void
      {
          this.myDockPanel.createComponent(this.DockPanelSettings);
      }
      
  • The following example demonstrates how to create a DockPanel component for Angular by using the createComponent method.

    import { Component, ViewChild, AfterViewInit } from '@angular/core';
    import { jqxDockPanelComponent } from 'jqwidgets-ng/jqxdockpanel';
    @Component({
    selector: 'app-root',
    template: `
    <jqxDockPanel #dockPanelReference [auto-create]='false'>
    <div id='first' dock='left' style='background: #486974;'>
    First Div
    </div>
    <div id='second' dock='top' style='height: 100px; background: #368ba7;'>
    Second Div
    </div>
    <div id='third' dock='right' style='background: #df7169;'>
    Third Div
    </div>
    <div id='fourth' style='background: #a73654;'>
    Fourth Div
    </div>
    </jqxDockPanel>`
    })
    export class AppComponent implements AfterViewInit
    {
    @ViewChild('dockPanelReference') myDockPanel: jqxDockPanelComponent;
    ngAfterViewInit(): void
    {
    this.myDockPanel1.createComponent({ width: 300, height: 210 });
    }
    }

Properties

The properties which are defined as attributes can be changed directly:

onSomeEventTriggered () {
this.width = 800;
this.height = 600;
}

To get or set a property, which we did not define or call a method, we can do the following:

  • Import @ViewChild decorator:

    import { Component, ViewChild } from '@angular/core';

  • Add the DockPanel component:

    <jqxDockPanel #dockPanelReference></jqxDockPanel>

  • Get access to the DockPanel component and its API:

    @ViewChild('dockPanelReference') myDockPanel: jqxDockPanelComponent;

  • Finally, we can set/get properties like that:


Every component has a method setOptions which accepts a JSON object as an argument. This object contains component settings and you can use it to set a single or multiple properties dynamically.

Events

The layout event occurs when the layout is performed.

The following example demonstrates how to add an event listener.

Note: Event Names of the DockPanel component for Angular are the same as the Event Names of the jqxDockPanel widget.
The only thing you need to do is to put "on" before the event name and upperCase it's the first letter.

DockPanel Examples

Overview

The following example demonstrates how to create a DockPanel component for Angular.

Disabling

The following example demonstrates how to disable DockPanel.

DockPanel API

API Reference of the jQWidgets DockPanel component for Angular: DockPanel API