DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • Zone-Free Angular: Unlocking High-Performance Change Detection With Signals and Modern Reactivity
  • When Angular APIs Return 200 but the Frontend Is Already Failing Users
  • Why Angular Performance Problems Are Often Backend Problems
  • Faster Releases With DevOps: Java Microservices and Angular UI in CI/CD

Trending

  • RAG Done Right: When to Use SQL, Search, and Vector Retrieval and How To Combine Them
  • Detecting Bugs and Vulnerabilities in Java With SonarQube
  • No More Cheap Claude: 4 First Principles of Token Economics in 2026
  • AWS Kiro: The Agentic IDE That Makes Specs the Unit of Work
  1. DZone
  2. Coding
  3. Frameworks
  4. Introduction to Angular Grid

Introduction to Angular Grid

In this post, we look at how to at ag-Grid to Angular applications, going over all the code and commands you'll need.

By 
Swathi Prasad user avatar
Swathi Prasad
·
May. 07, 19 · Tutorial
Likes (5)
Comment
Save
Tweet
Share
17.8K Views

Join the DZone community and get the full member experience.

Join For Free

Displaying and manipulating tabular data is often necessary in software applications. In this article, I will introduce ag-Grid for Angular applications. ag-Grid is implemented in TypeScript and can be used for displaying both simple and complex data. It also gives good user experience.

Adding ag-Grid to Angular Project

Create a project using Angular CLI and install ag-grid-community and ag-grid-angular through npm.

npm install --save ag-grid-community ag-grid-angular

Import the ag-Grid styles globally in styles.scss.

@import "~ag-grid-community/dist/styles/ag-grid.css"; 
@import "~ag-grid-community/dist/styles/ag-theme-blue.css";

The ag-grid.css imports Gird styles and ag-theme-blue.css is one of the available grid themes. There are many themes available within the module. You can either choose the one that matches your project design or customize styles through Sass variables.

Let's include the module app.module.ts.

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';

import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';

import { AgGridModule } from 'ag-grid-angular';

@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    BrowserModule,
    AppRoutingModule,
    AgGridModule.withComponents([])
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }

Here, the withComponents call is required to use Angular components in the grid.

Add the grid definition in app.component.ts.

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

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.scss']
})
export class AppComponent {
  title = 'Angular ag-Grid';

  columnDefs = [
        { headerName: 'Employee Name', field: 'name' },
        { headerName: 'Title', field: 'title' },
        { headerName: 'Employee Number', field: 'number' },
        { headerName: 'Date of Joining', field: 'date’  }
    ];

    rowData = [
        { name: 'John', title: 'Software Engineer', number: 123456, date: 'March 02, 2016' },
        { name: 'Jane', title: 'Senior Software Engineer', number: 123451, date: 'April 01, 2014' },
        { name: 'Richard', title: 'Software Engineer', number: 123452, date: 'January 02, 2015' },
        { name: 'Janie', title: 'Software Engineer', number: 123453, date: 'March 23, 2016' },
        { name: 'Johnny', title: 'Senior Software Engineer', number: 123454, date: 'September 01, 2017' }
    ];
}

We just added two properties i.e., column definitions and row data. Note that the row data can also be dynamically loaded. More information about column definition can be found here.

Let's add the grid component on app.component.html. Here is the complete HTML file.

<div style="text-align:center">
  <h1>
    Welcome to {{ title }}!
  </h1>
</div>

<ag-grid-angular
    style="width: 800px; height: 155px; margin: auto"
    class="ag-theme-blue"
    [rowData]="rowData"
    [columnDefs]="columnDefs">
</ag-grid-angular>

<router-outlet></router-outlet>

It is possible to add, sort, and filter features on the grid. Just add the feature in column definition as follows.

columnDefs = [
        { headerName: 'Employee Name', field: 'name', sortable:true, filter:true },
        { headerName: 'Title', field: 'title', sortable:true, filter:true },
        { headerName: 'Employee Number', field: 'number', sortable:true, filter:true },
        { headerName: 'Date of Joining', field: 'date', sortable:true, filter:true }
    ];

We can also add checkbox selection and multiple row selections to the grid.

columnDefs = [
        { headerName: 'Employee Name', field: 'name', sortable:true, filter:true, checkboxSelection: true },
        { headerName: 'Title', field: 'title', sortable:true, filter:true },
        { headerName: 'Employee Number', field: 'number', sortable:true, filter:true },
        { headerName: 'Date of Joining', field: 'date', sortable:true, filter:true }
    ];

In the HTML, just add the rowselection property.

<ag-grid-angular
    style="width: 800px; height: 155px; margin: auto"
    class="ag-theme-blue"
    [rowData]="rowData"
    [columnDefs]="columnDefs"
    rowSelection="multiple">
</ag-grid-angular>

Let us run the  ng serve command to see our little app. Here is the final app that shows ag-Grid.


Angular Grid

Conclusion

ag-Grid has many more features to offer and it is easy to integrate into Angular projects. Checkout their complete documentation here. The complete example for this article can be found on my GitHub repository.

AngularJS

Published at DZone with permission of Swathi Prasad. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • Zone-Free Angular: Unlocking High-Performance Change Detection With Signals and Modern Reactivity
  • When Angular APIs Return 200 but the Frontend Is Already Failing Users
  • Why Angular Performance Problems Are Often Backend Problems
  • Faster Releases With DevOps: Java Microservices and Angular UI in CI/CD

Partner Resources

×

Comments

The likes didn't load as expected. Please refresh the page and try again.

  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook