dojodgrid

Hide column in dgrid dynamically


How to hide complete column in dgrid (gridFromHtml) based on some run time parameter? Lets say if the value of parameter is true I should be able to display some column and if the value is false then I should be able to hide that same column.


Solution

  • Use grid.styleColumn(columnId, css):

    var grid = new Grid({
        store: store,
        columns: [
            { id: "artist", label: "Artist", field: "Artist"},
            { id: "name", label: "Song", field: "Name"},
            { id: "gerne", label: "Genre", field: "Genre"}
        ]
    }, "grid-placeholder");
    
    // to hide column with id="name"
    grid.styleColumn("name", "display: none;");
    
    // to show it
    grid.styleColumn("name", "display: table-cell;");