Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
119
rated 0 times [  122] [ 3]  / answers: 1 / hits: 63175  / 11 Years ago, fri, july 26, 2013, 12:00:00

How can we use Bootstrap to create <thead> with 2 levels (eg: Summer Period has hildren data1, data2, data3) and also table cells that merged 2 vertical cells (eg:State)?



Here's how it looks like in Excel:



enter


More From » jquery

 Answers
47

I'm not sure how exactly to do it with Bootstrap, but I know how to do it in HTML:






You can use a combination of the colspan and rowspan attributes, where rowspan is used for table headers spanning multiple rows, and the same applies to colspan and columns.




  1. Break up your table headers into rows, according to their levels.

    So the first table row will consist of your parent headers, i.e. the headers that every other header and piece of data is going to fall under.


  2. Your first row should have 3 columns: State, Utilities Company and Summer Period.


  3. Add subsequent header rows for each level you drill down. Here, your next row will simply be the table headers for each data set.







Let's apply the attributes:




  1. Your 1st th for State spans 2 rows, so we add rowspan=2.

  2. The same applies to the next table header, Utilities Company.

  3. Summer Period spans 1 row and 3 columns, so we add colspan=3

  4. Add another tr in the header, containing the 3 cells for data1, data2 and data3.



The resulting HTML looks like this:



<thead>
<tr>
<th rowspan=2>State</th>
<th rowspan=2>Utilities Company</th>
<th colspan=3>Summer Period</th>
</tr>
<tr>
<th>data1</th>
<th>data2</th>
<th>data3</th>
</tr>
</thead>





Here is a demo fiddle.



Here's an updated demo (actually reset as base) including bootstrap.css even though it literally does nothing demo fiddle updated.


[#76736] Thursday, July 25, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
lidialyrick

Total Points: 737
Total Questions: 104
Total Answers: 89

Location: Andorra
Member since Sat, May 27, 2023
1 Year ago
;