How to get started easily with Syncfusion Angular 11 Dashboard Layout?
The Essential JS 2 Angular DashboardLayout is a grid-structured layout component that helps create static and dynamic dashboard layouts with panels. Dashboard panels are the basic building blocks of a dashboard, and they can be added programmatically or dynamically at run time. The panels hold UI components and allows resizing, reordering, drag-and-drop, and adding-removing of panels. This allows users to easily place components at the desired position within this layout.
This KB article explains how to easily integrate Syncfusion Angular Dashboard Layout in an Angular 11 application with its commonly used features.
Prerequisites
Before starting, you need the following items to create an Angular Dashboard Layout in Angular 11 application:
- Node.js (Latest version)
- Angular 11
- Angular CLI
- Typescript 4+
- Visual Studio Code for Editor
Installation and application creation
- Install Angular cli 11 using following command.
npm install -g @angular/cli@11.2.3
If you want to follow and run the application in Angular 6, Angular 5, or Angular 4, you need to replace the CLI command version number with corresponding angular version number.
npm install -g @angular/cli@<CLI VERSION>
- Create an Angular 11 application using Angular cli.
ng new angular11-app cd angular11-app
- Serve the Angular 11 application using the following command.
ng serve --open
Listen to the application in localhost:4200. Your application will serve in browser. Refer to the following screenshot for Angular 11 version.
Integration of Angular Dashboard Layout
- After running the Angular 11 application successfully, configure the Angular Dashboard Layout in this application. Install Angular Dashboard Layout and EJ2 package using the following command.
npm install @syncfusion/ej2-angular-layouts --save npm install @syncfusion/ej2 --save
The --save command instructs the NPM to include a layout package that contains the Dashboard Layout control inside the dependencies section of the package.json.
- Import DashboardLayoutModule from installed package in app/app.module.ts.
import { BrowserModule } from '@angular/platform-browser'; import { NgModule } from '@angular/core'; import { DashboardLayoutModule } from '@syncfusion/ej2-angular-layouts'; import { AppComponent } from './app.component'; @NgModule({ declarations: [ AppComponent ], imports: [ BrowserModule, DashboardLayoutModule ], bootstrap: [AppComponent] }) export class AppModule { }
- Refer to the CSS file for Angular Dashboard Layout in style.CSS.
@import "../node_modules/@syncfusion/ej2-base/styles/material.css"; @import "../node_modules/@syncfusion/ej2-angular-layouts/styles/material.css";
- Add the Angular Dashboard Layout component in app.component.html.
<ejs-dashboardlayout></ejs-dashboardlayout>
- Now, define the columns, cellSpacing, and panels for Dashboard Layout in app.component.ts.
export class AppComponent implements OnInit { public cellSpacing: number[] = [20, 20]; public columns: number = 3; public panels: any = [ { "row": 0, "col": 0, content: '<div class="content">1</div>' }, { "row": 0, "col": 1, content: '<div class="content">2</div>' }, { "row": 0, "col": 2, content: '<div class="content">3</div>' }, { "row": 1, "col": 0, content: '<div class="content">4</div>' }, { "row": 1, "col": 1, content: '<div class="content">5</div>' }, { "row": 1, "col": 2, content: '<div class="content">6</div>' } ] }
- After defining these data, define Dashboard Layout’s columns, cellSpacing, and panels in app.component.html.
|
You can also use other functionalities such as allowResizing and cellAspectRatio.
- Now, serve the application using the following command.
ng serve --open
After all the files have been compiled successfully, it will serve the site at localhost:4200.
The following screenshot illustrates this.
Summary
You can check the features of Angular Dashboard Layout.
Also, refer to the documentation and online samples for more details on Dashboard Layout control.
If you have any queries or require clarifications, please let us know in comments below. You can also contact us through our Support forum or Direct-Trac. We are happy to assist you!