This is a migrated thread and some comments may be shown as answers.

Setting "Menu: False" dynamically?

2 Answers 106 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Lisa
Top achievements
Rank 1
Lisa asked on 13 Jul 2018, 05:35 PM

Hi - I have columns that I want to show in the ColumnMenu:columns or not based on a variable.  What I have right now on the column definition is " menu: false," but in some cases I do want the column to show up.  I tried making it a function, not even checking the variable yet:

                    menu: function (e)
                    {

                        return false
                    },

which doesn't work.  Is there a way to do this?

Thanks

Lisa

 

 

 

 

2 Answers, 1 is accepted

Sort by
0
Accepted
Attila Antal
Telerik team
answered on 17 Jul 2018, 12:05 PM
Hi Lisa,

It is advisable creating a separate method and call it when needed, thus the code will look more transparent and easy to be maintained.

Example:
menu: ShouldDisplay()
 
function ShouldDisplay(){
    if(ConditionMet){
        return true;
    }
     
    return false;
}

Initially, the reason the method did not work was because the column.menu property takes a boolean value and a function declaration was passed to it. To make it work, the function needs to be executed, and for that, place the round brackets to end of it. (see marked with yellow)

menu: function ()
{
    return false
}(),

You can also try the Dojo Sample for a Live demonstration.

Kind regards,
Attila Antal
Progress Telerik
Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Lisa
Top achievements
Rank 1
answered on 18 Jul 2018, 08:18 PM

Thank you, that worked great!

 

Lisa

Tags
Grid
Asked by
Lisa
Top achievements
Rank 1
Answers by
Attila Antal
Telerik team
Lisa
Top achievements
Rank 1
Share this question
or