Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating Accordion Table with Bootstrap

I have a table that's populated from a database which has lots of columns (around 30). A solution someone thought of was to create an accordion out the table, where each row is clickable and will accordion downwards with the rest of the columns worth of information. I am having trouble getting Bootstrap to do this properly for me.

<table class="table table-hover">     <thead>         <th></th><th></th><th></th>     </thead>      <tbody>         <tr data-toggle="collapse" data-target="#accordion" class="clickable">             <td>Some Stuff</td>             <td>Some more stuff</td>             <td>And some more</td>         </tr>         <tr>             <td>                 <div id="accordion" class="collapse">Hidden by default</div>             </td>         </tr>     </tbody> </table> 

As you can see from the jsfiddle, this functionality is not working. Im not really sure what's wrong, and Bootstrap's docs don't go into much detail on collapsing.

Any assistance would be greatly appreciated, thanks!

like image 848
jaredready Avatar asked Jun 10 '14 18:06

jaredready


1 Answers

This seems to be already asked before:

This might help:

Twitter Bootstrap Use collapse.js on table cells [Almost Done]

UPDATE:

Your fiddle wasn't loading jQuery, so anything worked.

<table class="table table-hover"> <thead>   <tr>     <th></th>     <th></th>     <th></th>   </tr> </thead>  <tbody>     <tr data-toggle="collapse" data-target="#accordion" class="clickable">         <td>Some Stuff</td>         <td>Some more stuff</td>         <td>And some more</td>     </tr>     <tr>         <td colspan="3">             <div id="accordion" class="collapse">Hidden by default</div>         </td>     </tr> </tbody> </table> 

Try this one: http://jsfiddle.net/Nb7wy/2/

I also added colspan='2' to the details row. But it's essentially your fiddle with jQuery loaded (in frameworks in the left column)

like image 181
josec89 Avatar answered Sep 24 '22 01:09

josec89