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 8603035
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T02:13:47+00:00 2026-06-12T02:13:47+00:00

I am trying to create a dynamic html table with retractable columns. In real

  • 0

I am trying to create a dynamic html table with retractable columns.
In real case, I can have 20 columns per header and up to 400 values.
I would like to present the data like this:

-----------------------------------------------------------
|    |            Header 1          | Header 2 | Header 3 |
-----------------------------------------------------------
|val1| col1.1 | col1.2 |...| col1.x | col 2.1  | col 3.1  |
-----------------------------------------------------------
|val2| col1.1 | col1.2 |...| col1.x | col 2.1  | col 3.1  |
-----------------------------------------------------------
 ...
-----------------------------------------------------------
|valx| col1.1 | col1.2 |...| col1.x | col 2.1  | col 3.1  |
-----------------------------------------------------------
|foot| foot1.1| foot1.2|...| foot1.x| foot2.1  | foot3.1  |
-----------------------------------------------------------

I want the ability to click on and colx.1, expand or show all the columns under the same header and collapse (or hide) other columns for other headers.
From the table above clicking on any col2.1 cell would then change the table to :

-----------------------------------------------------------
|    | Header 1 |            Header 2          | Header 3 |
-----------------------------------------------------------
|val1| col 1.1  | col2.1 | col2.2 |...| col2.x | col 3.1  |
-----------------------------------------------------------
|val2| col 1.1  | col2.1 | col2.2 |...| col2.x | col 3.1  |
-----------------------------------------------------------
 ...
-----------------------------------------------------------
|valx| col 1.1  | col2.1 | col2.2 |...| col2.x | col 3.1  |
-----------------------------------------------------------
|foot| foot1.1  | foot2.1| foot2.2|...| foot2.x| foot3.1  |
-----------------------------------------------------------

I have tried to do something like:
use hideable class on all td elements that can be shown/hidden
and to something like:

var rows = $('tr');
rows.find('th:eq(1), td:eq(1)').on('click', function() {
    $('.hideable').toggle()
});

I also need to change the colspan of headers and footers accordingly with

('th#foot1.1').attr('colspan',1)

The above solution works but is very inefficient and does not seem very clean.

Added simplified jsFiddle sample jsfiddle.net/yrMsX. The idea would be not to have header 1 and 2 expanded at the same time.

Is there a better, more effective way to achieve this?

  • 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-12T02:13:48+00:00Added an answer on June 12, 2026 at 2:13 am

    Ok I made this fiddle hope is what you were looking for.

    Basically you should focus on this:

    • give the header and its sub cols same class
    • set colspan attribute for those headers you want to toggle
    • set a data-fullcol attribute to each header to keep track of their maximum colspan
    • bind to click event only those columns with colspan attribute
    • give a first class to those columns you want to stay visible
    • on click event hide all columns whose class doesn’t equal the one of the clicked header and haven’t also a first class
    • sett all other headers colspan to 1
    • toggle all the columns with same class as the header you clicked one
    • to toggle the header’s colspan set colspan to (data-fullcol – colspan +1)

    NB : this will only work if headers have single classes, if you want to give ’em more than one class, consider saving the ‘important class’ in a specific attribute like data-class

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to make an editable table. I have a dynamic table, columns can
I am trying to create a dynamic bar in HTML using javascript. I have
I am trying to create a simple javascript html table so I can put
I am trying to create some dynamic html out of some data from db.
I am trying to create an html object dynamically with the necessary header information
I am trying to create an HTML table in HAML that has a first
I am trying to create two dynamic dates in html/javascript/jquery. I want the dates
I am trying to create dynamic html created from jquery and save it as
I am trying to create dynamic pages without creating new files and getting the
I am trying to create dynamic menus from the database using the following example

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.