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 Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
  1. DZone
  2. Data Engineering
  3. Databases
  4. How to Enable Column Hiding in Ignite UI for Angular Grid

How to Enable Column Hiding in Ignite UI for Angular Grid

Learn how to make a snazzy column that users can click to open and close using Angular Grid.

Dhananjay Kumar user avatar by
Dhananjay Kumar
·
Feb. 21, 19 · Tutorial
Like (2)
Save
Tweet
Share
6.74K Views

Join the DZone community and get the full member experience.

Join For Free

Ignite UI for Angular Grid is the fastest Angular Grid out there. It does not only run fast, it is also very easy to use igxGrid in your application. Ignite UI for the Angular Grid component class is named igxGrid and, on the template, it can be used as <igx-grid></igx-grid>.

In this blog post, let's learn how Column Hiding can be enabled in IgniteUI for Angular Grid.  

Step 1:  Add Ignite UI for Angular into Our Angular Project

There are three ways to add an igx-grid to an Angular project:

  1. If starting a new project, use the Ignite UI CLI to scaffold the project. You can use command line options to add the igx-grid, including dependency installation.
  2. In an existing project, you can use the Ignite UI for Angular Toolbox Extension to add an igx-grid in the project. Learn how in this blog post.
  3. You can use npm to install Ignite UI for Angular dependencies in your project. You can learn about that in detail here: Step-by-Step with Images to Add Ignite UI for Angular in an Existing Angular Project

Step 2: Add igx-grid to an Angular Project

To work with igxGrid, you need to add:

  1. igxGridModule 
  2. BrowserAnimationModule 
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { IgxGridModule } from 'igniteui-angular';

After importing, pass these two modules to the imports array module. Next, to bind with igxGrid, let's create a local data source in the component.

getData() {
    return [
        { model: 'BMW', color: 'Black', price: '20000' },
        { model: 'Audi', color: 'Blue', price: '10000' },
        { model: 'Merc', color: 'Red', price: '25000' },
        { model: 'Toyta', color: 'Green', price: '18000' },
        { model: 'GM', color: 'Blye', price: '10000' },
    ];
}

If you want to learn how to work with REST-based API and igxGrid, follow four simple steps to working with Ignite UI for Angular Grid and REST Services.

In the ngOnInit life cycle hook of the component, read data from getData() function as shown in the code listed below. We will set the data source for igxGrid to localData using property binding on the template.

ngOnInit() {
    this.localData = this.getData();
}

Add igxGrid on the template as shown in the code listing below. We are explicitly configuring columns such that, we can work with column hiding feature.

<igx-grid #grid1 id="grid1" [data]="localData" [autoGenerate]="false">
    <igx-column field="model" header="Maker"></igx-column>
    <igx-column field="color" header="Color"></igx-column>
    <igx-column field="price" header="Price"></igx-column>
</igx-grid>

In the above igxGrid:

  1. The columns are configured manually.
  2. The data source is set using the [data]property and binding it to localData.
  3. Since the columns are configured manually, autoGenerate is set to false.

At this point, you will get an igxGrid in your Angular application as shown in the image below:

Step 3:  Enable Column Hiding

When using Ignite UI for Angular Grid, place the column hiding the UI in the grid’s toolbar. You can use the grid’s toolbar dropdown to show or hide columns. So, the first step you need to do is set showToolbar  in the igx-grid element to true.

<igx-grid .... [showToolbar]="true" toolbarTitle="Cars" ...>

</igx-grid>

After setting showToolbar to true, you need to set columnHiding to true.

<igx-grid .... [columnHiding]="true" ...>

</igx-grid>

By setting a combination of showToolbar and columnHiding, you can work with column hiding in igxGrid. Putting everything together,  with column hiding and manual column configuration igx-grid will look like as shown in the code listing below:

<igx-grid #grid1 id="grid1" [data]="localData" [autoGenerate]="false"
            [showToolbar]="true" toolbarTitle="Cars" [columnHiding]="true">
      <igx-column field="model" header="Maker"></igx-column>
      <igx-column field="color" header="Color"></igx-column>
      <igx-column field="price" header="Price"></igx-column>
  </igx-grid>

At this point, you will find igxGrid rendered as shown in the image below:

You can also disable a column from hiding by setting the [disabledHiding] property to true. So you can disable the hiding of a column's module as shown in the code listing below:

<igx-grid #grid1 id="grid1" [data]="localData" [autoGenerate]="false"
          [showToolbar]="true" toolbarTitle="Cars" [columnHiding]="true">
    <igx-column field="model" [disableHiding]="true" header="Maker"></igx-column>
    <igx-column field="color" header="Color"></igx-column>
    <igx-column field="price" header="Price"></igx-column>
</igx-grid>


At this point on running application, you will find igxGrid rendered  with model column disabled for hiding shown in the image below:

Besides hiding columns, there aremany features to use with IgniteUI for Angular Grid, which make it the best grid for enterprise applications. Check out all features here.

Now you have seen that hiding columns is as simple as setting property binding. I hope you find this post useful.

Column (database) AngularJS

Published at DZone with permission of Dhananjay Kumar, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • Asynchronous HTTP Requests With RxJava
  • Kotlin Is More Fun Than Java And This Is a Big Deal
  • Why You Should Automate Code Reviews
  • Event Driven 2.0

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

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

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: