How to get started easily with Syncfusion Angular 7 Dashboard Layout
How to get started easily with Syncfusion Angular 7 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 7 application with its commonly used features.
Prerequisites
Before starting, you need the following items to create an Angular Dashboard Layout in Angular 7 application:
- Node.js (latest version)
- Angular
- Angular CLI
- Visual studio code for editor
Installation and application creation
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 7 application using Angular cli.
ng new angular7-app
cd angular7-app
- Serve the Angular 7 application using the following command.
ng serve
Listen to the application in localhost:4200. Your application will serve in browser. Refer to the following screenshot for Angular 7 version.
Integration of Angular Dashboard Layout
- After running the Angular 7 application successfully, configure the Angular Dashboard Layout in this application. Install Angular Dashboard Layout and EJ2 package using the following command. 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.
npm install @syncfusion/ej2-angular-layouts --save
npm install @syncfusion/ej2 --save
- 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.
<ejs-dashboardlayout id='defaultLayout' #defaultLayout [columns]='columns' [cellSpacing]='cellSpacing' [panels]='panels'> </ejs-dashboardlayout>
You can also use other functionalities such as allowResizing and cellAspectRatio.
- Now, serve the application using the following command.
ng serve
After all the files have been compiled successfully, it will serve the site at localhost:4200.
The following screenshot illustrates this.
Summary
The runnable sample application prepared from the above steps has been committed in this location. 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!