Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8559715
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T16:07:02+00:00 2026-06-11T16:07:02+00:00

I have a HTML table as shown in http://jsfiddle.net/Lijo/auny3/ . The table has 10

  • 0

I have a HTML table as shown in http://jsfiddle.net/Lijo/auny3/ . The table has 10 columns – divided into three col groups. I need to hide/show the colgroup named “Associate Info” (including its rows data) using buttons “Show Associate” and “Hide Associate”.

What is the best way (in terms of performance) for doing this using jQuery?

Please answer if you have a better answer than http://jsfiddle.net/Lijo/auny3/8/

Note: I am generating the table using ASP.Net GridView as given in
http://www.sacdeveloper.com/Community/Articles/tabid/86/ctl/ArticleView/mid/458/articleId/1/Group_columns_in_an_ASPNet_Gridview.aspx

Reference:

  1. http://jsfiddle.net/Lijo/auny3/8/

  2. http://jsfiddle.net/Lijo/auny3/12/

  3. http://jsfiddle.net/Lijo/auny3/11/

  4. http://jsfiddle.net/Lijo/auny3/13/

Selected Answer

  1. http://jsfiddle.net/Lijo/UqdQp/2/

enter image description here

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T16:07:04+00:00Added an answer on June 11, 2026 at 4:07 pm

    I have generalized the idea provided by @Pioul. Hence please upvote for @Pioul also if you like this answer. This generalized approach is available in http://jsfiddle.net/Lijo/UqdQp/10/

    References:

    1. Finding column index using jQuery when table contains column-spanning cells

    2. Select table cells based on the value in the cell

    CODE

    var associateStartElementString = "EmpID";
    var financialStartElementString = "Type";
    
    var associateHTMLElements;
    var financialHTMLElements;
    
    var associateHideClass = '.tableColGroupAssociate';
    var financialHideClass = '.tableColGroupTransaction';
    
    $(document).ready(function () {
    
    
    
    ////////Hide Sections
    
    
    //Associate Hide
    $('.associateHide').live("click", function (e) {
        e.preventDefault();
    
    
        var hideClass = associateHideClass; 
        associateHTMLElements = HideSection(hideClass, associateStartElementString);
    
        $('.btnAssociate').show();
    
    });
    
    //Financial Hide
    $('.financialHide').live("click", function (e) {
        e.preventDefault();
    
      var hideClass = financialHideClass ;
    
        financialHTMLElements = HideSection(hideClass, financialStartElementString);
    
        $('.btnFinancial').show();
    
    });
    
    
    ////SHOW 
    $('.btnAssociate').click(function()
    {
        associateHTMLElements.show();
    
          var firstHeaderLineElement = $(".resultGridTable").find(associateHideClass );
    
        firstHeaderLineElement.show(); 
    
    });
    
    
    $('.btnFinancial').click(function()
    {
        financialHTMLElements.show();
    
          var firstHeaderLineElement = $(".resultGridTable").find(financialHideClass );
    
        firstHeaderLineElement.show(); 
    
    });
    
    
    
    //Function 1
    function HideSection(hideClass, startElementString) 
    {
    
    var htmlElement = GetTableSections(hideClass, startElementString);
    
    var firstHeaderLineElement = $(".resultGridTable").find(hideClass);
    
    var variableToSet;
    
    if (!(htmlElement === undefined)) {
    
        variableToSet = htmlElement;
        htmlElement.hide();
        firstHeaderLineElement.hide();
    }
    
    return variableToSet;
    }
    
    
    //Function 2
    function GetTableSections(hideClass, referenceHeaderCellValue) {
    
    
    var firstHeaderLineElement = $(".resultGridTable").find(hideClass);
    var colspan = parseInt(firstHeaderLineElement.attr("colspan"));
    
    
    var startElementIndex = GetNonColSpanIndex(referenceHeaderCellValue);
    
    
    if (startElementIndex > 0) {
    
        startElementIndex = (startElementIndex - 1);
    
        var selectedElements = $("tr:gt(0)")
                                        .find("th:gt(" + startElementIndex + "):lt(" + colspan + "), td:gt(" + startElementIndex + "):lt(" + colspan + ")");
    
        return selectedElements;
    
    }
    
    
    }
    
    //Function 3
    function GetNonColSpanIndex(referenceHeaderCellValue) {
    
    
    var selectedCell = $("th").filter(function (i) {
        return ($.trim($(this).html())) == referenceHeaderCellValue;
    
    
    });
    
    
    var allCells = $(selectedCell).parent('tr').children();
    var normalIndex = allCells.index($(selectedCell));
    var nonColSpanIndex = 0;
    
    
    allCells.each(
        function (i, item) {
            if (i == normalIndex)
                return false;
    
            var colspan = $(selectedCell).attr('colspan');
            colspan = colspan ? parseInt(colspan) : 1;
            nonColSpanIndex += colspan;
        }
        );
    
    return nonColSpanIndex;
    };
    
    
    }
    );
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a HTML table as shown in http://jsfiddle.net/Lijo/JN8Pm/1/ . This table is generated
I have HTML and CSS as shown in http://jsfiddle.net/Lijo/Ydjde/ The problem is the text
http://jsfiddle.net/Cyjye/ I m new to jquery. I have made html table shown in jsfiddle.Firstly
I need to set the table cell width as 300 as shown in http://jsfiddle.net/Lijo/Q3pa2/3/
I have HTML table as shown below. It has seven columns. I am adjusting
I have checkboxes as shown in http://jsfiddle.net/Lijo/Fw3fz/ . I need to align the checkboxes
I have an html table with one of the headers spanning over 2 columns.
I have an HTML table of tickets listings (e.g. http://seatgeek.com/event/show/23634/buffalo-bills-vs-tennessee-titans/ ). I'd like to
I have a HTML Table which is similar to the one shown (demo.jpg) in
I have HTML table. I'm looping through table and iterate over each row whose

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.