Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
495
Showing/hiding ALL columns ?
posted

Hello,

I'm wondering if it's possible to show or hide all of the columns with the Column Hiding feature? In the documents, I can only see ways to show or hide things, but nothing like a "show all" or "hide all" or even "reset". I'm trying to figure out an elegant way to save column visibility templates, and I don't see a method to send both visible and hidden at once.

Thanks,

Alex

Parents
  • 6279
    Suggested Answer
    posted

    Hi Alex,

    I'm afraid that the grid doesn't offer a "show all/hide all" functionality out of the box.
    I'd also like to make notice of the design decision which we took when we implemented the igGrid:
    The grid must display at least one column. 
    (and when you think about it, if there are no columns to show, why display an entire grid at all?)

    With this in mind, you can apply all kinds of code tricks in order to "hide" or show all columns.
    For example you can hide the entire grid when there are no columns to display using either of these approaches:

    //If you want to collapse the space that would otherwise be taken by the lack of a grid
    $("#Grid1").hide();
    //If you want to keep the space on the page that would be taken by the lack of a grid
    $("#Grid1").css('visibility','hidden');
    


    Also, here's a sample "show all columns" function:

    function showAllColumns()
    {
        //Just in case the the grid was hidden before
        if($("#Grid1").css('visibility') === "hidden")
        {
            $("#Grid1").css('visibility','visible');
        }
        else 
        {
            $("#Grid1").show();
        }
        
        var gridColumns = $("#Grid1").igGrid("option", "columns");
        
        for(var i = 0; i < gridColumns.length; i++)
        {
            if(gridColumns[i].hidden)
            {
                $("#Grid1").igGrid("showColumn", gridColumns[i].key);
            }
        }
    }
    

    I'm also attaching a working HTML sample page where you can see my suggestions in effect.

    Hope this helps,
    Borislav 
    t78380.zip
Reply Children