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

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

Last call! Secure your stack and shape the future! Help dev teams across the globe navigate their software supply chain security challenges.

Modernize your data layer. Learn how to design cloud-native database architectures to meet the evolving demands of AI and GenAI workloads.

Releasing software shouldn't be stressful or risky. Learn how to leverage progressive delivery techniques to ensure safer deployments.

Avoid machine learning mistakes and boost model performance! Discover key ML patterns, anti-patterns, data strategies, and more.

Related

  • Change Column in Syncfusion TreeGrid Angular
  • Rediscovering Angular: Modern Advantages and Technical Stack
  • Angular Input/Output Signals: The New Component Communication
  • Azure Deployment Using FileZilla

Trending

  • Fixing Common Oracle Database Problems
  • Scaling Mobile App Performance: How We Cut Screen Load Time From 8s to 2s
  • Analyzing “java.lang.OutOfMemoryError: Failed to create a thread” Error
  • Enhancing Security With ZTNA in Hybrid and Multi-Cloud Deployments
  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.

By 
Dhananjay Kumar user avatar
Dhananjay Kumar
·
Feb. 21, 19 · Tutorial
Likes (2)
Comment
Save
Tweet
Share
7.5K 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.

Related

  • Change Column in Syncfusion TreeGrid Angular
  • Rediscovering Angular: Modern Advantages and Technical Stack
  • Angular Input/Output Signals: The New Component Communication
  • Azure Deployment Using FileZilla

Partner Resources

×

Comments

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

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

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 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends: