1
<table id='mytab'>
    <tr>
        <td colspan="6">OS</td>
    </tr>
    <tr>
        <td></td>
        <td>Fedora</td>
        <td>Cent Os</td>
        <td>Ubuntu</td>
        <td>Suse</td>
        <td>Redhat</td>
    </tr>
    <tr>
        <td colspan="6">Versions</td>
    </tr>
    <tr>
        <td></td>
        <td>6</td>
        <td>v2.4</td>
        <td>beta 2</td>
        <td>8</td>
        <td>2008</td>
    </tr>    
    <tr>
        <td></td>
        <td>7</td>
        <td>v3.4</td>
        <td>1</td>
        <td>9</td>
        <td>2009</td>
    </tr>
    <tr>
        <td></td>
        <td>10</td>
        <td>v4.4</td>
        <td>2</td>
        <td>10</td>
        <td>2010</td>
    </tr>        
    <tr>
        <td colspan="6">Support</td>
    </tr>
    <tr>
        <td></td>
        <td>All Support Free</td>
        <td>Partial Support</td>
        <td>Paid Support</td>
        <td>Community Support</td>
        <td>Full support</td>
    </tr>
</table>

jquery

      $('#mytab td').hide();
      $('#mytab td:nth-child(1)').show();
     $('#mytab td:nth-child('whatever_column_selected')').show();

whenever whatever_column_selected, it's suppose to show the selected column, it's displaying and also displaying OS,version and support

so what I want is if suse is seleced then it's suppose to display in the following format: OS - > Suse

Versions - > 8 9 10

Support - > Community Support

If I need to replace the tables to div to get the output desired results, that'll also work

Thanks in advance

7
  • Selected how? Are there links on that first row? Behavior attached directly to the tds? Commented Jul 28, 2010 at 4:31
  • I'm confused how can you select Suse? to the fact that it is hidden... hmmm... Commented Jul 28, 2010 at 4:39
  • there is a javascript function so whenever somebody clicks on the fedora or suse or whatever that cell will get attached. Links are onto the second line Commented Jul 28, 2010 at 4:40
  • once you click on the suse, it'll hide other (fedora,cent,ubuntu and redhat). Commented Jul 28, 2010 at 4:42
  • @dave, so initially or are visible? Commented Jul 28, 2010 at 4:42

1 Answer 1

1

I have the html here with few changes..

$(function(){  
    $('#mytab tr.header td').click(function(){
        var index = $(this).index() + 1;
        $('#mytab tr td:nth-child(' + index + ')').siblings().hide();
    })
});​

update demo

$(function(){

    $('th').each(function(){
        var text = $(this).text();
        $(this).data('text',text);
    });
    $('#mytab tr.header td').click(function(){
        var index = $(this).index() + 1;
        $('#mytab tr:has(th)').each(function(){
            var str = $(this).nextUntil('tr:has(th)')
                .find(':nth-child('+index+')').map(function(){
                return $(this).text();
            }).get().join(" ");
            $(this).find('th').html(function(){
                return $(this).data('text') + '<span>--&gt; ' + str + '</span>';
            })
        });
    })
});​
Sign up to request clarification or add additional context in comments.

10 Comments

Thanks Reigel for the answer but there is no problem in show/hide. There is the problem in display of Data. If something is clicked/selected then the format of display is suppose to be like this <table> <tr> <td> OS</td><td> Suse </td> </tr> <tr> <td>Versions </td> <td>8</td> <td> 9</td> <td> 10 </td> </tr> <tr> <td>Support </td> <td> Community Support </td> </tr> <table> Thanks
oh?.. you want it to display as like a string? like put OS - > Suse Versions - > 8 9 10 Support - > Community Support below the table?
I m sorry if my words are confusing, suse's versions are listed in three different rows, 8 9 10, so whenever version is displayed, it's supposed to be on the left side, and 8 9 10 on the right hand side. (Version is currently displayed first then on the next row 8 and next row 9 and last one is 10) so all is suppose to be in one line.
So a click on a column should generate a new table, two columns, "summarizing" the original column's data?
just replace return $(this).text(); with return $(this).html(); inside the .map(function(){...})...
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.