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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T19:39:56+00:00 2026-05-14T19:39:56+00:00

I want to create a table where each row has an expandable details row.

  • 0

I want to create a table where each row has an expandable details row. See the below simplified example code. Upon clicking a row in the visible table, the corresponding row from the hidden table should be cloned and inserted below the clicked row — thus creating an expanded row effect. A second click removes the details row.

The problem is that in IE8 (and possibly other versions) when the second or third row is expanded, the width of the columns change. The first row doesn’t. The difference appears to be the length of the content in the details row. Viewing this same example in Firefox 3.5, you’ll see the columns maintain their original widths regardless of the length of the detail content. Why does this happen and how can it be fixed?

The attached jQuery is 1.2.6, but the effect should be the same regardless of the version.

<html>
<head>
    <style type="text/css">
        table#primary {
            width: 504px;
            border-collapse: collapse;
        }
        table#primary,
        table#primary tr,
        table#primary th,
        table#primary td, {
            padding: 0;
            margin: 0;
        }
        table#primary td {
            border: 1px solid black;
        }
        td.time {
            width: 100px;
        }
        td.title {
            width: 300px;
        }
        td.room {
            width: 100px;
        }
        table#secondary {
            display: none;
        }
    </style>
    <script type="text/javascript" src="scripts/jquery.js"></script>
    <script type="text/javascript">
        $(document).ready(function() {
            $("table#primary tr").click(function() { 
                toggleDetails($(this));
            });
        });

        function toggleDetails(row) {
            if (row.hasClass("expanded")) {
                hideDetails(row);
            } else {
                showDetails(row);
            }
        }

        function showDetails(row) {
            var id = row.attr("id");
            var detailsRow = $("tr#details_" + id).clone(true);
            detailsRow.insertAfter(row);
            row.addClass("expanded");
        }

        function hideDetails(row) {
            row.removeClass("expanded");
            row.next().remove();
        }
    </script>
</head>
<body>

<table id="primary">
    <thead>
        <th>Time</th>
        <th>Title</th>
        <th>Room</th>
    </thead>
    <tbody>
        <tr id="one">
            <td class="time">11:00 am</td>
            <td class="title">First</td>
            <td class="room">101A</td>
        </tr>
        <tr id="two">
            <td class="time">12:00 pm</td>
            <td class="title">Second</td>
            <td class="room">206A</td>
        </tr>
        <tr id="three">
            <td class="time">1:00 pm</td>
            <td class="title">Third</td>
            <td class="room">103B</td>
        </tr>
    </tbody>
</table>

<table id="secondary">
    <tbody>
        <tr id="details_one">
            <td colspan="3">Lorem ipsum one. Lorem ipsum one.</td>
        </tr>
        <tr id="details_two">
            <td colspan="3">Lorem ipsum two. Lorem ipsum two. Lorem ipsum two. Lorem ipsum two. Lorem ipsum two. Lorem ipsum two.</td>
        </tr>
        <tr id="details_three">
            <td colspan="3">Lorem ipsum three. Lorem ipsum three. Lorem ipsum three. Lorem ipsum three. Lorem ipsum three. Lorem ipsum three. Lorem ipsum three. Lorem ipsum three. Lorem ipsum three. Lorem ipsum three. Lorem ipsum three. Lorem ipsum three. Lorem ipsum three. Lorem ipsum three. Lorem ipsum three. Lorem ipsum three. Lorem ipsum three. Lorem ipsum three. Lorem ipsum three. Lorem ipsum three. Lorem ipsum three. Lorem ipsum three. Lorem ipsum three. Lorem ipsum three. Lorem ipsum three. Lorem ipsum three. Lorem ipsum three. Lorem ipsum three. Lorem ipsum three. Lorem ipsum three. Lorem ipsum three. Lorem ipsum three. Lorem ipsum three.</td>
        </tr>
    </tbody>
</table>

</body>
</html>
  • 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-05-14T19:39:57+00:00Added an answer on May 14, 2026 at 7:39 pm

    when the second or third row is expanded, the width of the columns change.

    Yeah, you’ll need style table-layout: fixed on the <table> if you want your widths to be actually respected. Otherwise you are at the mercy of the auto table layout algorithm, which is generally unpredictable (and especially wonky in IE when colspan is involved).

    With fixed table layout you set the explicit widths on the cells in the first row of the table, or, better, on <col> elements. And they actually stick. Plus it renders quicker.

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

Sidebar

Related Questions

I want to create a table representing data I have, but I want each
I have a table create table Profiles (id int, xml_data xml ) that has
I have a simple hierarchy of categories in an SQLite3 database, each row storing
I want grouped ranking on a very large table, I've found a couple of
I've got the following table: CREATE TABLE `products_quantity` ( `id` int(11) NOT NULL auto_increment,
CREATE TABLE exmp_test ( id int, v1 int, v2 int, v3 int, v4 int
I have a situation in which I don't want inserts to take place (the
I have a CakePHP 1.2 application. I'm running into the case where I need
I am currently messing around with some stuff for an idea for a site

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.