views:

59

answers:

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

+1  A: 

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>';
            })
        });
    })
});​
Reigel
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
dave
oh?.. you want it to display as like a string? like put `OS - > Suse Versions - > 8 9 10 Support - > Community Support` below the table?
Reigel
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.
dave
So a click on a column should generate a new table, two columns, "summarizing" the original column's data?
Ken Redler
phew!... I hope this one is right.. ;) http://jsfiddle.net/X2DBv/1/
Reigel
yes correct that's what exactly required.Thanks Reigel
dave
cool!.... don't forget to accept correct answers... :)
Reigel
ofcourse.I m going to accept it :)
dave
Suppose there are images in one column then how can that be done ? Thanks in advance
dave
just replace `return $(this).text();` with `return $(this).html();` inside the `.map(function(){...})`...
Reigel
yes, it worked . Many thanks
dave
Hello Reigel,instead of using $('#mytab tr.header td').click(function(){I m calling my own onclick functionit's working fine, but everytime it's called, TH's Data is not getting replaced. Means if OS is having Suse, after clicking of other or same column it's adding data after suse instead of replacing it with the suse.and it's happening in every row.Please helpThanksDave
dave
can you save a copy here http://jsfiddle.net/ for me to look at...
Reigel
Alright I m going to copy paste it my code there
dave
Hello Reigel,can you tell me how to remove the data of TH on some button's click, and I'll try to solve that problem of repeating.Thanks in adcance
dave
Well, you could post your problem here at SO, that would be nice.. :)
Reigel
Thanks Reigel,There was a glitch in my code, And now my problem is solved :)Thanks for the support
dave