Write Applications Fast Using Ignite UI Grid


Write web applications faster with Ignite UI for JavaScript/HTML5 and ASP.NET MVC . You can use the Ignite UI for JavaScript library to help quickly solve complex LOB requirements in HTML5, jQuery, Angular, React, or ASP.NET MVC. Use the Ignite UI for JavaScript library to add a fast, responsive grid with many features (like pagination, sorting, search, virtualization etc.). It takes just a few minutes using a few lines of code. Ignite UI for JavaScript has many controls, data visualizations charts, and framework elements that are simple to configure and customize. The ease of Ignite UI for JavaScript control configurations and customizations allows you to create a web application quickly.

In addition to seamlessly rendering large sets of data, the Ignite UI for JavaScript Grid features many valuable tools, such as filtering, paging, and sorting. Learn more about Ignite UI for JavaScript features on the Ignite UI product page; you can also learn more about Angular in Angular Essentials, a free eBook published by Infragistics.

Lesson Objectives

  1. Add Ignite UI for JavaScript grid
  2. Configure grid columns

See Ignite UI Data Grid for more information on controls used in this lesson.

At the end of this lesson, you will have a working grid configured for columns in an Angular application. See the Ignite UI for JavaScript Angular components page on Github to learn more about working with Ignite UI for JavaScript in Angular.

Setting up the Project

You may download the starter project for this lesson by clicking here. (You can also download the final project by clicking here.)

After downloading the project, navigate to the directory and run the commands below:

  • npm install
  • npm start

You have executed the npm install command to install all dependencies, using the npm start command to run the Angular application. If the project setup is correct, you will have a running Angular application as shown in the image below:

Setting up project with Ignite Grid

Step 1 Import and Declare the Component

To work with Ignite UI Angular components, you must import and declare them in the module. For example, to use the igGrid component in an Angular application, import and declare the IgGridComponent in the application module.

In the project, navigate to the Finance App folder and then to the app folder. Open the file app.module.ts, and add the import statements below, just after the existing import statements.

import{IgGridComponent} from 'igniteui-angular2';
import {GridComponent} from './grid.component';

After importing the required components, you must declare them in the application module. Add IgGridComponent and GridComponent in the AppModule’s declaration array. Modify @NgModule decorator in app.module.ts as shown below:

imports: [BrowserModule,HttpModule],
declarations: [AppComponent,
              IgGridComponent, GridComponent],
              providers: [AppService],
              bootstrap: [AppComponent]
export class AppModule { }

You have added IgGridComponent and GridComponent in the declaration array of AppModule module. We will examine other added components and properties (like providers) in subsequent lessons.

Step 2 Create a Data Source

You need data to bind to the grid. This data can be a JavaScript array or a JSON object array and can be local or provided by a REST service.

Ideally, you should create a function to return data in an Angular service so you can use the data function in multiple components. However, for this lesson, there is already a function called getData in GridComponent class. This function returns a JSON object array.

In the app folder, open the file grid.component.ts and find the getData() function. In later lessons, you will learn how to create a grid that uses data from the REST services.

Step 3 Get Data

To use data returned from the getData() function, call the function inside Angular ngOnInit() life cycle hook and assign a returned value to the GridComponent property.

To learn more, see Lifecycle Hooks.

In the app folder, open the file grid.component.ts and modify the ngOnInit() function as shown in the listing below:

  this.stocks = this.getData();

Step 4 Create a Grid

The Ignite UI for JavaScript Grid component can be used like any other component. In the app folder, open the file grid.component.html, and add the code as shown in the below listing:

<ig-grid widgetId="grid1" [dataSource]="stocks" [autoGenerateColumns]="true">

Step 5 Use in an Application

To use the GridComponent in an application: in the app folder, open the app.component.html file and add the code below just at the end of all of the markup. Add it below the


Navigate to the application, scroll down, and, at the bottom of the page, you will find the grid added as shown in the image below:

Use Ignite Grid in an application

Step 6 Configure Columns of the Grid

In Step 4, you created a grid by setting the autoGenerateColumns property to true. You didn’t need to configure the columns of the grid and they were generated automatically.

In many cases you may need to configure columns manually. You can configure columns and other features such as paging, sorting, and filtering of the grid in the component class.

To configure columns: in the app folder, open grid.component.ts file, and update ngOnInit() function in grid.component.ts file with the listing below:

ngOnInit() {
  this.stocks = this.getData();
  this.gridId = "Grid1";
  this.gridOptions = {
    dataSource: this.stocks,
    autoGenerateColumns: false,
    columns: [
        { headerText: "CLOSE", key: "Close", dataType: "number" },
        { headerText: "DATE", key: "Date", dataType: "string" },
        { headerText: "HIGH", key: "High", dataType: "number" },
        { headerText: "LOW", key: "Low", dataType: "number" },
        { headerText: "OPEN", key: "Open", dataType: "number" },
        { headerText: "VOLUME", key: "Volume", dataType: "number" }

Step 7 Modify the Grid with Configured Columns

Ignite UI for JavaScript's Angular grid options and widgetId properties are enabled for two-way data binding, so any changes in the source will be reflected on the grid. To set options and widgetId properties: in the app folder, open the file grid.component.html, and modify it as shown in the below listing:

<ig-grid [(options)]= "gridOptions" [(widgetId)]="gridId">

Navigate to the application and scroll to the bottom of the page to find the grid added as shown below:

Modify Grid with configured columns


Ignite UI for JavaScript can help you write web applications more quickly. In addition to Angular, Ignite UI for JavaScript may be used with React, AngularJS, jQuery, and ASP.NET MVC.