How to show/hide a WebGrid column including header/footer

21 replies. Last post: April 7, 2011 10:25 AM by Shawn August
Tags :
  • (None)
  • New Discussion
  • New Question
  • New Product Feedback
Shawn AugustMember

I have been using the following JavaScript to show/hide a WebGrid column including the header/footer. This works fine for WebGrids that do not have horizontal scrollbars. As soon as the user scrolls causing the "hidden" fields to be out of view, they re-appear after the user scrolls back.

Is there a better way to ensure the header/column/footer are hidden? I'd prefer something by name assuming performance isn't compromised.

function WebGrid_ShowHideColumnByPos(gridID, position, show) 
{
    var grid = WebGrid_GetGrid(gridID);
    if (grid == null) { return; }
    var rootTable = grid.GetRootTable();
    var row = rootTable.GetElement(WG40.BODY, WG40.HTMLTABLE);
    
    // Get the header and column groups
    headerGroup = rootTable.GetElement(WG40.COLHEADER, WG40.HTMLDIV);
    colGroup = rootTable.GetElement(WG40.COLGROUP, WG40.HTMLDIV);

    // Show/Hide
    var styleDisplay = "none";
    if (show == true) { styleDisplay = ""; } else { styleDisplay = "none"; }
    headerGroup.childNodes[0].childNodes[0].childNodes[0].childNodes[position].style.display = styleDisplay;
    colGroup.childNodes[position].style.display = styleDisplay;
}
All times are GMT -5. The time now is 5:49 AM.
Previous Next