Setting "Menu: False" dynamically?

3 posts, 1 answers
  1. Lisa
    Lisa avatar
    37 posts
    Member since:
    May 2011

    Posted 13 Jul 2018 Link to this post

    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. Answer
    Attila Antal
    Admin
    Attila Antal avatar
    591 posts

    Posted 17 Jul 2018 Link to this post

    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.
  3. Lisa
    Lisa avatar
    37 posts
    Member since:
    May 2011

    Posted 18 Jul 2018 in reply to Attila Antal Link to this post

    Thank you, that worked great!

     

    Lisa

Back to Top