Merge Column Into Rows In Html Table - html

Rowspan And Colspan For Building HTML Tables.
I want the first five column in a single row without any data as shown in editable fig. ,Can use rowspan or colspan.
Only The Last Two Column is as it is as shown in the editable fig. And There should be a row before that two column which is the combination of the five columns and that should be blank.
<div class="row">
<div class="col-12">
<table>
<thead>
<tr>
<th>Savings for holiday!</th>
<th>Date!</th>
<th>Year</th>
<th>Month</th>
<th>Time</th>
<th>Name</th>
<th>Gender</th>
</tr>
</thead>
<tbody>
<tr>
<td>$100</td>
<td>10/10/2020</td>
<td>2020</td>
<td>January</td>
<td>4:30pm</td>
<td>hrishi</td>
<td>male</td>
</tr>
</tbody>
<tbody>
<tr>
<td>$100</td>
<td>10/10/2020</td>
<td>2020</td>
<td>January</td>
<td>4:30pm</td>
<td>hrishi</td>
<td>male</td>
</tr>
</tbody>
</table>
</div>
</div>

See the code below.
<table>
<tr>
<th colspan="5" rowspan="3" width="300"></th>
<th>Name</th>
<th>Gender</th>
</tr>
<tr>
<td>hrishi</td>
<td>male</td>
</tr>
<tr>
<td>hrishi</td>
<td>male</td>
</tr>
</table>

I applied the bootstrap css class in css file and got my answer.
<table>
<tr>
<th colspan="5" rowspan="3" class="w-70"></th>
<th>Name</th>
<th>Gender</th>
</tr>
<tr>
<td>hrishi</td>
<td>male</td>
</tr>
<tr>
<td>hrishi</td>
<td>male</td>
</tr>
</table>
And add the width property in style.css file -
.w-70 {
width: 70%;
}

Related

Nested ( master detail ) table in html

I added child table in tr but I am unable to make a grid like shown in mockup.
Basically, I got the idea from dev extreme grid. https://js.devexpress.com/Demos/WidgetsGallery/Demo/DataGrid/MasterDetailView/Angular/Light/
You should be able to use further <tr>, <td>, <th> elements to do what you need, since it seems like you want to keep the same table layout for the pseudo-child-tables:
<table>
<thead>
<tr>
<th>Teader Id</th>
<th>Name</th>
<th>address</th>
<th></th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>ABC</td>
<td>32 block</td>
<td></td>
</tr>
<tr>
<th></th>
<th>Student Id</th>
<th>Name</th>
<th>Gender</th>
</tr>
<tr>
<td></td>
<td>11</td>
<td>DEF</td>
<td>Male</td>
</tr>
<tr>
<td>2</td>
<td>GHI</td>
<td>32 block</td>
<td></td>
</tr>
<tr>
<th></th>
<th>Student Id</th>
<th>Name</th>
<th>Gender</th>
</tr>
<tr>
<td></td>
<td>12</td>
<td>JKL</td>
<td>Male</td>
</tr>
<tr>
<td>3</td>
<td>MNO</td>
<td>32 block</td>
<td></td>
</tr>
<tr>
<th></th>
<th>Student Id</th>
<th>Name</th>
<th>Gender</th>
</tr>
<tr>
<td></td>
<td>11</td>
<td>PQR</td>
<td>Male</td>
</tr>
</tbody>
</table>

nesting table inside a <td> to match the <th> of outside table

table,
th,
td {
border: 1px solid black;
}
<html>
<table style="border:1px solid;">
<thead>
<tr>
<th rowspan="2">Type</th>
<th colspan="2">Client</th>
<th rowspan="2">Currency</th>
<th rowspan="2">Amount</th>
<th rowspan="2">Monthly Total</th>
<th rowspan="2">Yearly Total</th>
</tr>
<tr>
<th>Name</th>
<th>Id</th>
</tr>
</thead>
<tbody>
<tr>
<td>Customer</td>
<td colspan="4">
<table style="width:100%">
<tr>
<td>Client A</td>
<td>1234</td>
<td>USD</td>
<td>200</td>
</tr>
<tr>
<td>Client B</td>
<td>5678</td>
<td>USD</td>
<td>200</td>
</tr>
</table>
</td>
<td>300</td>
<td>500</td>
</tr>
<tr>
<td>Vendor</td>
<td colspan="4">
<table>
<tr>
<td>Client C</td>
<td>5678</td>
<td>GBP</td>
<td>100</td>
</tr>
</table>
</td>
<td>300</td>
<td>500</td>
</tr>
</tbody>
</table>
</html>
I have to achieve the above structure , but I am unable to align the inner table to match the width of the from the outer table . tried many things but unable to do it. Could some one please help me ?
So I have a two *ngFor nested , the first one is for the outer table tbody and the second one is for a row for the inner table.
Should you be nesting the table? I would use rowspan instead otherwise your table structure is not semantically correct
table,
th,
td {
border: 1px solid black;
}
<html>
<table style="border:1px solid;">
<thead>
<tr>
<th rowspan="2">Type</th>
<th colspan="2">Client</th>
<th rowspan="2">Currency</th>
<th rowspan="2">Amount</th>
<th rowspan="2">Monthly Total</th>
<th rowspan="2">Yearly Total</th>
</tr>
<tr>
<th>Name</th>
<th>Id</th>
</tr>
</thead>
<tbody>
<tr>
<td rowspan="2">Customer</td>
<td>Client A</td>
<td>1234</td>
<td>USD</td>
<td>200</td>
<td rowspan="2">300</td>
<td rowspan="2">500</td>
</tr>
<tr>
<td>Client B</td>
<td>5678</td>
<td>USD</td>
<td>200</td>
</tr>
<tr>
<td>Vendor</td>
<td>Client C</td>
<td>5678</td>
<td>GBP</td>
<td>100</td>
<td>300</td>
<td>500</td>
</tr>
</tbody>
</table>
</html>
This kind of thing can be very fiddly. I suggest you save yourself the headache with:
<th>Client Name</th><th>Client ID</th>
If you really have to achieve this structure, use colspan and rowspan.

Make TH equals to 3 columns in HTML

Hello, I want to make ACTIONS equal to three columns
As shown in image, I want ACTIONS in center of Detail Update Delete
Please help.
<table border=1>
<tr>
<th>NAME</th>
<th>AGE</th>
<th colspan="3">ACTIONS</th>
</tr>
<tr>
<td>Salman Mushtaq</td>
<td>27</td>
<td>Detail</td>
<td>Update</td>
<td>Delete</td>
</tr>
<tr>
<td>Muhanmmad Awais</td>
<td>32</td>
<td>Detail</td>
<td>Update</td>
<td>Delete</td>
</tr>
</tr>
<tr>
<td>Imran Hassan</td>
<td>38</td>
<td>Detail</td>
<td>Update</td>
<td>Delete</td>
</tr>
</tr>
<tr>
<td>Muhammad Asad</td>
<td>33</td>
<td>Detail</td>
<td>Update</td>
<td>Delete</td>
</tr>
</table>
Try to search about colspan and rowspan
Use colspan attribute in TH tag (ie. colspan="3")
<table border="1">
<thead>
<tr>
<th>Name</th>
<th>Age</th>
<th colspan="3">Action (spanned 3 cols)</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>2</td>
<td>action 1</td>
<td>Action 2</td>
<td>Action 3</td>
</tr>
</tbody>
</table>

Merge columns into single cell

I create a table and what I want is to merge some cells in the last row to show the total or summary. I tried to put some CSS but it didn't work.
this the table I have.
<table class="table table-bordered">
<thead>
<tr>
<th>Class</th>
<th>A</th>
<th>B</th>
<th>Total</th>
</tr>
</thead>
<tr>
<td>1</td>
<td>25</td>
<td>27</td>
<td>52</td>
</tr>
<tr>
<td>2</td>
<td>24</td>
<td>26</td>
<td>50</td>
</tr>
<tr>
<!-- merge -->
<td></td>
<td></td>
<td>Total</td>
<!-- merge -->
<td>102</td>
</tr>
</table>
what I want is to merge the first 3 in the last row
how can I do that?
thanks!
You could use colspan to specify which cells that you would like combined.
<table class="table table-bordered">
<thead>
<tr>
<th>Class</th>
<th>A</th>
<th>B</th>
<th>Total</th>
</tr>
</thead>
<tr>
<td>1</td>
<td>25</td>
<td>27</td>
<td>52</td>
</tr>
<tr>
<td>2</td>
<td>24</td>
<td>26</td>
<td>50</td>
</tr>
<tr>
<td colspan="3">Total</td>
<td>102</td>
</tr>
</table>
I think it would be:
<td colspan="3"> This is Bigger! </td>
That is merging horizontally.
If you want to merge vertically, you would have to say
<th rowspan="2"> This is also bigger, but different! </th>

Table with two rows, one row only for title - HTML

I am trying to make a table with two rows and multiple columns in html. I want the first row to have only one space instead of two for each column. It will be a title space for the entire table.
Example: (Specifications is the Title)
[Specifications]
[Power ][200 Lumens ]
[Lamp ][4 Ultrabright LEDs, Maxbright LED]
[Burn Time ][150 Hours ]
Use colspan="2"
<table border="1">
<tr>
<th colspan="2">Specifictaions</th>
</tr>
<tr>
<td>Power</td>
<td>200 Lumens</td>
</tr>
<tr>
<td>Lamp</td>
<td>4 Ultrabright LEDs, Maxbright LED</td>
</tr>
<tr>
<td>Burn Time</td>
<td>150 Hours</td>
</tr>
</table>
Fiddle: http://jsfiddle.net/tCvBn/
Screenshot
If there is just one section to the table (viz: all the table contents are specifications) I'd probably use a caption element to mark that up:
<table>
<caption>Specifications</caption>
<tr>
<th scope="row">Power</th>
<td>200 Lumens</td>
</tr>
<tr>
<th scope="row">Lamp</th>
<td>4 Ultrabright LEDs, Maxbright LED</td>
</tr>
<tr>
<th scope="row">Burn Time</th>
<td>150 Hours</td>
</tr>
</table>
If there are multiple sections, I'd use the spanning (<th scope="col" colspan="2">... table headers:
<table>
<tr>
<th scope="col" colspan="2">Specifications</th>
</tr>
<tr>
<th scope="row">Power</th>
<td>200 Lumens</td>
</tr>
<tr>
<th scope="row">Lamp</th>
<td>4 Ultrabright LEDs, Maxbright LED</td>
</tr>
<tr>
<th scope="row">Burn Time</th>
<td>150 Hours</td>
</tr>
<tr>
<th scope="col" colspan="2">Some Other Section</th>
</tr>
<tr>
<th scope="row">Foo</th>
<td>Bar</td>
</tr>
<tr>
<th scope="row">Baz</th>
<td>Qux</td>
</tr>
</table>
fiddle
I believe this is what you're looking for! Here is a demo
<table width="100" border="1">
<tr>
<th colspan="2">Foo</th>
</tr>
<tr>
<td>Foo</td>
<td>Bar</td>
</tr>
<tr>
<td>Foo</td>
<td>Bar</td>
</tr>
<tr>
<td>Foo</td>
<td>Bar</td>
</tr>
</table>