Skip to content

Infragistics Community Forum / Web / Ignite UI for jQuery / How to hide igGrid columns dynamically

How to hide igGrid columns dynamically

New Discussion
Charles Craven-Bartl
Charles Craven-Bartl asked on Jan 23, 2017 12:43 PM

I have a combo box with two entries for types of User : Standard and Authoriser

I have a igGrid that lists the users – a simplified view of the column definitions is shown below.

columns: [{
key: ‘UserId’,
dataType: ‘string’,
headerText: ‘User Id’,
hidden: false
}, {
key: ‘UserName’,
dataType: ‘string’,
headerText: ‘User Name’,
hidden: false
},{
key: ‘SpendLimit’,
dataType: ‘number’,
headerText: ‘Spend Limit’,
hidden: false
}]

When the combo box ‘Standard’ option is selected I want the SpendLimit column to be hidden completely as this property is not valid for Standard users.  When the combo box ‘Authoriser’ option is selected I want the SpendLimit column to become visible again as this property is valid for Authorisers – each Authoriser has a spend limit.

Basically, I just want to bind to the hidden property of the SpendLimit column setting hidden to true if the Standard option is selected and setting hidden to false if the Authoriser option is selected.

How do I do this?  (I don’t want to use the hiding feature which allows the user to show or hide columns as the SpendLimit column should never be visible for the Standard users.)

Sign In to post a reply

Replies

  • 0
    Charles Craven-Bartl
    Charles Craven-Bartl answered on Jan 23, 2017 9:56 AM

    I don't know why I didn't think of this first: I just set up a boolean variable for each column that may be hidden and set the grid column hidden property to evaluate that variable value:

    var hideSpendLimit = false;

    if (user.isAuthoriser === true){

    hideSpendLimit = false;

    } else {

    hideSpendLimit = true;

    }

    ,{
    key: 'SpendLimit',
    dataType: 'number',
    headerText: 'Spend Limit',
    hidden: hideSpendLimit
    }

    • 0
      Charles Craven-Bartl
      Charles Craven-Bartl answered on Jan 23, 2017 10:55 AM

      Actually, this still doesn't work as it seems that the hidden property is only referenced when the grid is initialised.  If another user is selected which changes the hideSpendLimit value this is not being picked up and evaluated by the column hidden property at run time.  

      Any ideas any one?

       

      • 0
        Ivaylo Hubenov
        Ivaylo Hubenov answered on Jan 23, 2017 12:43 PM

        Hello Charles,

        A column cannot change its state (hidden or shown) dynamically.

        What you could do is destroy the grid and render it again with the new "hideSpendLimit" value. For example:


        $("#combo").igCombo({
            ... ,
            selectionChanged: function(evt, ui) {
                $("#grid").igGrid("destroy");
                $("#grid").igGrid({
                    //grid definition
                }
            }
        });

        Please feel free to contact me if you need further assistance.

        Regards,
        Ivaylo Hubenov
        Entry-level developer

  • You must be logged in to reply to this topic.
Discussion created by
Favorites
Replies
Created On
Last Post
Discussion created by
Charles Craven-Bartl
Favorites
0
Replies
3
Created On
Jan 23, 2017
Last Post
9 years, 2 months ago

Suggested Discussions

Created on

Jan 23, 2017 12:43 PM

Last activity on

Feb 20, 2026 12:37 PM