Table inside a table HTML - html

I am have my HTML that have a table inside odd two
I want this
but I have this
How can I do the table td with the same ?
This is my code in HTML:
<table>
<thead class='thead-dark'>
<tr>
<th>Semestre</th>
<th>Curso</th>
<th>Seccion</th>
</tr>
</thead>
<tbody>
{% for item in results%}
<tr>
<td>{{item.year}}</td>
<td><table class="table table-striped table-hover">
{% if item.A!= ""%}
<tr><td><p>A.1</p></td></tr>
{%endif%}
{% if item.B != ""%}
<tr><td><p>B.1</p></td></tr>
{%endif%}
</tr></table></td>
<td><table>
{% if item.A != ""%}
<tr><td><p>{{item.A|linebreaks}}</p></td></tr>
{%endif%}
{% if item.B != ""%}
<tr><td><p>{{item.B|linebreaks}}</p></td></tr>
{%endif%}
</tr></table></td>
</tr>
</tbody>
</table>

You don't have to nest a second table in it. Using "rowspan" as #Brian Tomspett suggested will do the trick.
table {
border-collapse: collapse;
}
td, th {
border: 1px solid black;
}
<table>
<tbody>
<tr>
<td>Item1</td>
<td>Item2</td>
<td>Item3</td>
</tr>
<tr>
<td rowspan="6">A</td>
<td rowspan="2">A.1</td>
<td>A.1.1</td>
</tr>
<tr>
<td>A.1.2</td>
</tr>
<tr>
<td rowspan="2">A.2</td>
<td>A.2.1</td>
</tr>
<tr>
<td>A.2.2</td>
</tr>
<tr>
<td rowspan="2">A.2</td>
<td>A.3.1</td>
</tr>
<tr>
<td>A.3.2</td>
</tr>
<!--continue the pattern here-->
</tbody>
</table>

Related

Display two td's in seperate line

I have two td's under one tr. How can i show the 2nd td in next line.Currently its displaying in same line.I would have to loop the users object and its content multiple times.
<table>
<thead>
<tr>
<th>Name</th>
<th>Status</th>
</tr>
</thead>
<tbody>
<tr v-for="(user,index) in users" :key="index">
<td>
{{ user.id}}
</td>
<td>
<table>
<tbody>
<tr v-for="(info,index) in user.demographic" :key="index">
<td>
{{info.name}}
</td>
<td>
{{info.address}}
</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>

Style first table row of group identified by td classname sibling to another row

How can I do to change the style of the first row of a group of rows (identified by a td with a sub-item class) that is near to a sibling row (identified by a td with the item class):
HTML:
<table>
<thead>
</thead>
<tbody>
<tr>
<td class="item"></td>
</tr>
<tr>
<td class="sub-item"><!-- I need to style this one --></td>
</tr>
<tr>
<td class="sub-item"></td>
</tr>
<tr>
<td class="sub-item"></td>
</tr>
<tr>
<td class="item"></td>
</tr>
<tr>
<td class="sub-item"><!-- I need to style this one --></td>
</tr>
</tbody>
</table>
I'd like to style with an inset box-shadow all the first rows matched by this criteria.
I tried with the sibling operator without success:
CSS:
tr > td.item ~ tr > td.sub-item:first {}
With the current code you would have to use :nth-[last]-child()
tr:first-child + tr .sub-item, tr:nth-last-child(2) + tr .sub-item {
background-color: red
}
<table>
<thead>
</thead>
<tbody>
<tr>
<td class="item">1</td>
</tr>
<tr>
<td class="sub-item">2<!-- I need to style this one --></td>
</tr>
<tr>
<td class="sub-item">3</td>
</tr>
<tr>
<td class="sub-item">4</td>
</tr>
<tr>
<td class="item">5</td>
</tr>
<tr>
<td class="sub-item">6<!-- I need to style this one --></td>
</tr>
</tbody>
</table>
Also, you can add a class to tr and achieve what you want.
.row + tr .sub-item {
background-color: red
}
<table>
<thead>
</thead>
<tbody>
<tr class="row">
<td class="item">1</td>
</tr>
<tr>
<td class="sub-item">2<!-- I need to style this one --></td>
</tr>
<tr>
<td class="sub-item">3</td>
</tr>
<tr>
<td class="sub-item">4</td>
</tr>
<tr class="row">
<td class="item">5</td>
</tr>
<tr>
<td class="sub-item">6<!-- I need to style this one --></td>
</tr>
</tbody>
</table>

How to align table cells center left?

I have a simple table structure.
table > tbody > tr > td{
text-align:center;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.0.0-beta/css/bootstrap.css" rel="stylesheet"/>
<table class="table table-hover">
<thead>
<tr>
<td>Client</td>
</tr>
</thead>
<tbody>
<tr>
<td class="col-md-4">
C 1
</td>
</tr>
<tr>
<td class="col-md-4">
Client 2
</td>
</tr>
</tbody>
</table>
The question is : How can I align td-s content left and center. ?
The output should be something like this :
If you are wanting the lower cells to be left justified from the centre, then just add padding-left 50% to your body cells
.table tbody td {
padding-left: 50%;
text-align;
left;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.0.0-beta/css/bootstrap.css" rel="stylesheet" />
<table class="table table-hover">
<thead>
<tr>
<td>Client</td>
</tr>
</thead>
<tbody>
<tr>
<td class="col-md-4">
C 1
</td>
</tr>
<tr>
<td class="col-md-4">
Client 2
</td>
</tr>
</tbody>
</table>
If you want them centred to the largest word, then left-aligned, you cannot have separate rows for the tbody, you would need to wrap all the words in an inline block div:
.col-md-4 {
text-align: center;
}
.inline-block {
display: inline-block;
text-align: left;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.0.0-beta/css/bootstrap.css" rel="stylesheet" />
<table class="table table-hover">
<thead>
<tr>
<td>Client</td>
</tr>
</thead>
<tbody>
<tr>
<td class="col-md-4">
<div class="inline-block">
C 1<br> Client 2
</div>
</td>
</tr>
</tbody>
</table>
Try this:
td {
width: 50%;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.0.0-beta/css/bootstrap.css" rel="stylesheet"/>
<table class="table table-hover">
<thead>
<tr>
<td>Client</td>
<td></td>
</tr>
</thead>
<tbody>
<tr>
<td>
</td>
<td>
C 1
</td>
</tr>
<tr>
<td>
</td>
<td>
Client 2
</td>
</tr>
</tbody>
</table>
If you can't add extra table-cells you could use padding:
.table tbody td {
padding-left: 50%;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.0.0-beta/css/bootstrap.css" rel="stylesheet"/>
<table class="table table-hover">
<thead>
<tr>
<td>Client</td>
</tr>
</thead>
<tbody>
<tr>
<td>
C 1
</td>
</tr>
<tr>
<td>
Client 2
</td>
</tr>
</tbody>
</table>
td {
width: 50%;
}
td:last-child {
border-left:1px solid #333;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.0.0-beta/css/bootstrap.css" rel="stylesheet"/>
<table class="table table-hover">
<thead>
<tr>
<td>Client</td>
<td></td>
</tr>
</thead>
<tbody>
<tr>
<td>
</td>
<td>
C 1
</td>
</tr>
<tr>
<td>
</td>
<td>
Client 2
</td>
</tr>
</tbody>
</table>
Try colspan="<number of columns to merge>" and rowspan="<number of rows to merge>" to merge row or column:
<table>
<thead>
<tr>
<td colspan="2" align="center">Client</td>
</tr>
</thead>
<tbody>
<tr>
<td rowspan="2" width="50%"></td>
<td>
C 1
</td>
</tr>
<tr>
<td>
Client 2
</td>
</tr>
</tbody>
</table>

How to add new table inside tr in new line?

I have one table:
<table>
<tr>
<td (click)="expend()">aaaa</td>
<table>
<tr><td>bbbb</td></tr>
</table>
</tr>
</table>
Now what i want is to add new table for that row so on top i will have that tr and bellow i will have that new table. Any suggestion?
EDIT:
This is my full table:
<table class="custom-table">
<tr dnd-draggable [dragData]="sa" (onDragStart)="dnd.set(true);" (onDragEnd)="dnd.set(false)" *ngFor="let sa of customerGeneralInfo?.serviceAccount" (click)="sa?.accountclassCode=='SAGG' ? getSAGG(sa.p_SA_ID):getServiceAccount(sa.p_SA_ID,'CA');addToHistory('CA')">
<td>{{sa?.p_SA_ID}}</td>
<td>{{sa?.address}}</td>
<td *ngIf="sa?.accountclassCode=='SAGG'">{{sa?.accountclassCode}}</td>
<td style="display:block">
<table *ngIf="saggInfo?.serviceAccount?.length > 0">
<tr *ngFor="let saggsa of saggInfo?.serviceAccount">
<td>
{{saggsa?.p_SA_ID}}
</td>
<td>
{{saggsa?.address}}
</td>
</tr>
</table>
</td>
</tr>
</table>
What i want to achive to have this:
aaaaaa -first row
bbbbb - second table
ccccc -second row
something like this?
<table>
<tr>
<td (click)="expend()">aaaa</td>
</tr>
<tr>
<td>
<table>
<tr><td>bbbb</td></tr>
</table>
</td>
</tr>
</table>
Added borders to see where each table begins and ends...
Edited
table {
border: 1px solid #aaa;
}
<table class="custom-table">
<tr dnd-draggable [dragData]="sa" (onDragStart)="dnd.set(true);" (onDragEnd)="dnd.set(false)" *ngFor="let sa of customerGeneralInfo?.serviceAccount" (click)="sa?.accountclassCode=='SAGG' ? getSAGG(sa.p_SA_ID):getServiceAccount(sa.p_SA_ID,'CA');addToHistory('CA')">
<td>{{sa?.p_SA_ID}}</td>
<td>{{sa?.address}}</td>
<td *ngIf="sa?.accountclassCode=='SAGG'">{{sa?.accountclassCode}}</td>
</tr>
<tr>
<td colspan="3">
<table *ngIf="saggInfo?.serviceAccount?.length > 0">
<tr *ngFor="let saggsa of saggInfo?.serviceAccount">
<td>{{saggsa?.p_SA_ID}}</td>
<td>{{saggsa?.address}}</td>
</tr>
</table>
</td>
</tr>
</table>

how to set position of div according to table height

i make a table in which rows are dynamically inserted and then i make a div below table when table height increase due to more rows the div does not show ho i set the position of a div when increase table height the div automatically below the table?
here is my code:
<div id="table">
<table class="table table-bordered">
<thead>
<tr>
<th>Description</th>
<th>Quantity</th>
<th>Price</th>
<th>Total</th>
</tr>
</thead>
<tbody>
{% for invoice in invoices %}
<tr>
<td style="color:black;">{{ invoice.description }}</td>
<td style="text-align:right; color:black;">{{ invoice.quantity }}</td>
<td style="text-align:right; color:black;">{{ invoice.unitPrice }}</td>
<td style="text-align:right; color:black;">{{ invoice.linetotal }}</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
<div style="width:243px; height:67px; float:right; margin:0px 215px 0; border:1px solid black;">
<h5> Invoice Total(USD) {{invoiceamount}}</h5>
<h5> Paid to date {{paidamount}}</h5>
<div class="horizontalRule2" runat="server"></div>
<h5> Invoice Total(USD) {{balanceamount}}</h5>
</div>
and here is table css:
#table{
float: right;
height: 110px;
margin: 4px 215px 0;
width: 686px;
}
here is screenshot i want div show below the table:
I think in this case I think you should stick with a table for those 2 cells as well, since somehow they are part of the tabulated data.
That means you could you just add them at
<div id="table">
<table class="table table-bordered">
<thead>
<tr>
<th>Description</th>
<th>Quantity</th>
<th>Price</th>
<th>Total</th>
</tr>
</thead>
<tbody>
{% for invoice in invoices %}
<tr>
<td style="color:black;">{{ invoice.description }}</td>
<td style="text-align:right; color:black;">{{ invoice.quantity }}</td>
<td style="text-align:right; color:black;">{{ invoice.unitPrice }}</td>
<td style="text-align:right; color:black;">{{ invoice.linetotal }}</td>
</tr>
{% endfor %}
<td colspan="3" style="text-align:right;"><h5>Invoice Total(USD)</h5></td>
<td style="text-align:right;"><h5>{{invoiceamount}}</h5></td>
<td colspan="3" style="text-align:right;"><h5>Paid to date(USD)</h5></td>
<td style="text-align:right;"><h5>{{balanceamount}}</h5></td>
</tbody>
</table>
</div>
Try clearing the div#table or the totals div that is below:
div#table {
clear:both;
}