How to add new table inside tr in new line? - html

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>

Related

How to disable the "table" tag behavior

If there is an overlapping join on different rows of the table, then the row may disappear:
<table border="1" bordercolor="#999" cellspacing="0px" cellpadding="2px" width="100%">
<tbody>
<tr>
<td rowspan="2">
<div>R1C1:R2C1 (row 1)</div>
</td>
<td>
<div>R1C2 (row 1)</div>
</td>
</tr>
<tr>
<td rowspan="2">
<div>R2C2:R3C2 (row 2)</div>
</td>
</tr>
<tr>
<td>
<div>R3C1 (row 3 should not be here)</div>
</td>
</tr>
</tbody>
</table>
This is unacceptable. May have to abandon the "table" tag. What to do?
It's not 100% clear what you mean. But I've removed the rowspan's and added colspan's to the code. Colspan will span your cell over multiple columns/cells.
More info can be found here:
https://www.w3schools.com/tags/att_td_colspan.asp
<table border="1" bordercolor="#999" cellspacing="0px" cellpadding="2px" width="100%">
<tbody>
<tr>
<td>
<div>R1C1:R2C1 (row 1)</div>
</td>
<td>
<div>R1C2 (row 1)</div>
</td>
</tr>
<tr>
<td colspan="2">
<div>R2C2:R3C2 (row 2)</div>
</td>
</tr>
<tr>
<td colspan="2">
<div>R3C1 (row 3)</div>
</td>
</tr>
</tbody>
</table>
You've included two td elements on the first row of your table, but only one td element on the second and third rows of your table, which will break your table layout - the browser doesn't know which column the cell is supposed to span. Fix this and your table should work.
There a couple of problems:
Table wrongly formatted (make sure the number of td matches, even if they are empty)
<table>
<thead>
<tr>
<th></th>
<th></th>
</tr>
</thead>
<tbody>
<tr>
<td></td>
<td></td>
</tr>
</tbody>
</table>
Styles wrongly applied (apply them by using <style> or referencing a stylesheet)
<table style="color:white;background-color:black;">
Extra: Don't use so many divs
While there isn't exactly a problem with using the divs you are using, using too many of them will usually lead to bad practices.
You can use some CSS tricks to hide border of last column so that the table is aligned as per your requirement.
table td.last {
border-left: hidden;
border-top:hidden;
}
table td.last2 {
border-left: hidden;
border-bottom:hidden
}
<table border="1" bordercolor="#999" cellspacing="0px" cellpadding="2px" width="100%">
<tbody>
<tr>
<td rowspan="2">
<div>R1C1:R2C1 (row 1)</div>
</td>
<td colspan="2">
<div>R1C2 (row 1)</div>
</td>
</tr>
<tr>
<td rowspan="2" style="border-right:hidden">
<div>R2C2:R3C2 (row 2)</div>
</td>
<td class="last2"><br></td>
</tr>
<tr>
<td>
<div>R3C1 (row 3 should not be here)</div>
</td>
<td class="last"><br></td>
</tr>
</tbody>
</table>

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>

HTML <table> cells following a "complete" rowspan not working as expected

I'm trying to make a fairly simple table with a rowspan, and it works as expected. However, the problem is with cells appearing after the all the spanned cells are resolved; they are not positioned where I think they should be.
Here's my code:
<html>
<body>
<table width="100%" border="1">
<tr>
<td rowspan="7">
7 row
</td>
<td>
1 row
</td>
</tr>
<tr>
<td>
1 row
</td>
</tr>
<tr>
<td rowspan="5">
5 row
</td>
</tr>
<tr>
<td>
<i>This shouldn't be here, but below and aligned to the left side of the table</i>
</td>
<td>
<i>This shouldn't be here, but below and aligned at the right side of the table</i>
</td>
</tr>
</table>
</body>
</html>
Here's how it renders in Chrome and Firefox (I don't have the reputation to post inline images at Stack Overflow):
http://embernet.com/misc/rowspan.gif
Those two wordy cells really should be in the columns 1 and 2 that were already established, not as new columns 3 and 4.
The problem seems to come from me spanning rows that are never individually realized. Keep in mind this is part of a larger, dynamically generated table that in some cases will show each of the 7 rows. I know someone will inevitably ask why I need to do this.
I don't see anything in the specs that suggests I cannot rowspan like this, so I'm hoping I'm just missing something obvious.
A JSFiddle is here: https://jsfiddle.net/mLard575/
I am not sure what you are expecting. I give two possibilities as per my understanding.
Choose as per your requirements
First Method:
table {
border-collapse: collapse;
}
td {
padding: 20px;
border: 1px solid black;
text-align: center;
}
<body>
<table>
<tbody>
<tr>
<td rowspan="7">7</td>
<td> 1 </td>
</tr>
<tr>
<td> 1 </td>
</tr>
<tr>
<td rowspan="5"> 5 </td>
</tr>
<tr>
<td> 1 </td>
</tr>
<tr>
<td> 1 </td>
</tr>
<tr>
<td> 1 </td>
</tr>
<tr>
<td> 1 </td>
</tr>
<tr>
<td> 1 </td>
<td> 1 </td>
</tr>
</tbody>
</table>
</body>
Second Method:
table {
border-collapse: collapse;
}
td {
padding: 20px;
border: 1px solid black;
text-align: center;
}
<body>
<table>
<tbody>
<tr>
<td rowspan="7">7</td>
<td> 1 </td>
</tr>
<tr>
<td> 1 </td>
</tr>
<tr>
<td> 1 </td>
</tr>
<tr>
<td> 1 </td>
</tr>
<tr>
<td> 1 </td>
</tr>
<tr>
<td> 1 </td>
</tr>
<tr>
<td> 1 </td>
</tr>
<tr>
<td> 1 </td>
<td> 1 </td>
</tr>
</tbody>
</table>
</body>
If these two methods are not suited for you. Just explain little bit more with diagram example to update the code.

Move to top inner table

How I close this gap between the inner table and the main table cell?
https://jsfiddle.net/w7eekbcL/2/
<td>
<table style="width:100%">
<tr>
<td colspan="2" style="font-family:verdana; color:#424242">main list</td>
</tr>
<tr>
<td colspan="2">list</td>
</tr>
<tr>
<td colspan="2">• one</td>
</tr>
<tr>
<td colspan="2">• second</td>
</tr>
<tr>
<td colspan="2">• thurd</td>
</tr>
</table>
</td>
For example I tried to use text-aligment but the result is the same.
Add vertical-align: top to the td that contains the table.

HTML table with different number of rows

I have a simple question :
we usually use
<table>
<tr>
<td> stuff1 </td>
<td> stuff2 </td>
<tr>
...
</table>
Therefore i can have on line with 3 columns and another with 4 columns. But I would like to do the contrary : on column with 3 rows and one column with 4 rows.
<table>
<td>
<tr> stuff1 </tr>
<tr> stuff2 </tr>
<td>
...
</table>
but swapping <tr> and <td> does not seem to works...
You can do that using rowspan property. Here is a clue :
table tr td {
border: 1px solid black;
}
<table>
<tr>
<td rowspan="2">left</td>
<td>T-right</td>
</tr>
<tr>
<td>B-Right</td>
</tr>
</table>
You can achieve this by using the rowspan attribute. It works exactly like colspan. http://www.w3schools.com/tags/att_td_rowspan.asp
<table>
<tr>
<td rowspan="2"></td>
<td></td>
</tr>
<tr>
<td></td>
</tr>
</table>