HTML: How to fill rows that 1st row is parent and following rows are children using AngularJs - html

I'm having an Angular Js like this
function Ctrl($scope) {
$scope.gardens = [
{garden:'1', trees: ["a", "b", "c", "d"]},
{garden:'2', trees: ["e", "f", "g", "h"]},
{garden:'3', trees: ["i", "k", "l", "m"]}
];
}
Now I want to display it in an html table as follow:
|Garden|Tree|
|1 |
| |a |
| |b |
| |c |
...
|2 |
| |e |
| |f |
| |g |
I can do this manually with DOM but have no solution with AngularJS.
(What I tried on html code:
<table ng-app="" ng-controller="Ctrl">
<tr ng-repeat="garden in gardens">
<td>{{garden.garden}}</td>
</tr>
</table>
)
Please help!
Johnny

You can do like this:
http://jsfiddle.net/ffVeu/
This is a base, just use it to produce a prettier HTML ;)
HTML
<div ng-app>
<table ng-controller="Ctrl">
<tr>
<th>Garden</th>
<th>Tree</th>
</tr>
<tr ng-repeat="garden in gardens">
<td class="firstColumn">{{garden.garden}}</td>
<td>
<table>
<tr ng-repeat="tree in garden.trees"><td>
{{tree}}
</td>
</tr>
</table>
</td>
</tr>
</table>
</div>
CSS (ugly, just to show the result, do not use this...)
</style> <!-- Ugly Hack due to jsFiddle issue: http://goo.gl/BUfGZ -->
<link rel="stylesheet"
href="http://twitter.github.com/bootstrap/assets/css/bootstrap.css">
<script
src="http://ajax.googleapis.com/ajax/libs/angularjs/1.0.3/angular.min.js">
</script>
<style>
.done-true {
text-decoration: line-through;
color: grey;
}
.firstColumn{
vertical-align: top;
}
table, tr, td {
padding: 2px;
margin: 20px;
text-align: center;
}
th {
background-color: silver;
color: white;
font-weight: bold;
padding: 10px;
}
tr{
border: 1px solid silver;
}
tr tr{
border: none;
}

Related

Single table cell to be full width on another row

I have a table mark-up that looks like the below:
-----------------
| a | b | c | d |
-----------------
On a different breakpoint, I would like the 'd' cell to shift below and go full width.
-------------
| a | b | c |
-------------
| d |
-------------
Is this possible with css?
You could use a media query and flexbox to override the default table styles.
table {
border-collapse: collapse;
display: block;
}
tr {
display: flex;
flex-wrap: wrap;
}
td {
border: 1px solid #ddd;
display: inline;
flex: 1;
padding: 5px 10px;
text-align: center;
}
td.d {
flex: 3;
flex-basis: 100%;
}
<table>
<tr>
<td>A</td>
<td>B</td>
<td>C</td>
<td class="d">D</td>
</tr>
</table>

html css table if empty cell change row color [duplicate]

This question already has answers here:
Is there a CSS parent selector?
(33 answers)
Closed 3 years ago.
I'm trying to make a table css that should change the row color if a cell in that row is empty
As far as I can see there is "empty":
<style type="text/css">
td:empty {
background-color: red;
}
</style>
Is there a way to change all the row color and not just the cell?
This is my actual table style:
<style type="text/css">
.tg {
border-collapse: collapse;
border-spacing: 0;
}
.tg td {
font-family: Arial, sans-serif;
font-size: 14px;
padding: 10px 5px;
border-style: solid;
border-width: 1px;
overflow: hidden;
word-break: normal;
border-color: black;
}
.tg th {
font-family: Arial, sans-serif;
font-size: 14px;
font-weight: normal;
padding: 10px 5px;
border-style: solid;
border-width: 1px;
overflow: hidden;
word-break: normal;
border-color: black;
}
.tg .tg-yofg {
background-color: #9aff99;
text-align: left;
vertical-align: top
}
.tg .tg-7od5 {
background-color: #9aff99;
border-color: inherit;
text-align: left;
vertical-align: top
}
.tg .tg-m9y7 {
background-color: #ffffc7;
text-align: left;
vertical-align: top;
border-left: 3px solid red;
}
#media screen and (max-width: 767px) {
.tg {
width: auto !important;
}
.tg col {
width: auto !important;
}
.tg-wrap {
overflow-x: auto;
-webkit-overflow-scrolling: touch;
}
}
</style>
My concern:
Does it exist?
IF yes: can I use it in my style?
If it exists but I cannot use it in my style, what should I change?
But mostly, as always when I try something out of my knowledge, is really this approach the best approach?
Just 2 lines as background:
I'm using python with jinja2 template to print an HTML table based on a python dictionary. I merge two dictonaries into one and then "jinja" it. It works, but I want to highlight the differences between them, the actual result:
|dict1-el1 | dict1-el2 | dict2-el1 | dict2-el2|
|-----------------------------------------------|
| a | b | | a | b |
| | f | | d | f |
| t | z | | t | z |
I would like the second row highlighted
This table has to be send by mail.
the column of dict1 are already styled with a color and the columns of the dict2 with another (in my case I have 7 column per dict).
A very BAD solution I thought was to pass not only the values "a", "b", etc etc to jinja, but to store in the merged dictionary itself the syle css name. I can then use python to chose the cell color. But before this I wonder if a css solution could easily exists.
Please give priority to css question.
Thanks
In CSS is not possibile, in javascript you could loop over all the rows, look for any empty cell and, if found, apply a class on the row
var rows = document.querySelectorAll('tr');
[...rows].forEach((r) => {
if (r.querySelectorAll('td:empty').length > 0) {
r.classList.add('highlight');
}
})
.highlight td {
background: yellowgreen;
}
<table cellspacing="0">
<tr>
<td>1</td>
<td></td>
<td>3</td>
<td>4</td>
</tr>
<tr>
<td>5</td>
<td>6</td>
<td>7</td>
<td>8</td>
</tr>
<tr>
<td>9</td>
<td>10</td>
<td></td>
<td>12</td>
</tr>
</table>

How to justify css table cells?

Well basically I have a css table that looks like this
-------------------------------------------------------------
| First | Middle1 | Middle2 | Last |
-------------------------------------------------------------
I'm looking to get this design
-------------------------------------------------------------
| First | Middle1 | Middle2 | Last |
-------------------------------------------------------------
First column is aligned to left, middle columns are aligned to center, and last column is aligned to right. Currently I'm using a solution that targets :first-child and :last-child in order to align them specifically. Is there a better/smarter way?
Align attributes are now deprecated. They still work in terms of aligning content but generally should not be used. Use CSS pseudo-element selectors to target the first and last cell in each row.
td {
text-align: center;
}
tr td:first-child {
text-align: left;
}
tr td:last-child {
text-align: right;
}
Use the td align attribute:
td {
min-width:100px;
border:1px solid black;
}
<table>
<tr>
<td align="left">Left</td>
<td align="center">Center</td>
<td align="center">Center</td>
<td align="right">Right</td>
</tr>
</table>
Using CSS:
td {
text-align: center;
}
td:nth-child(1)
{
text-align: left;
}
td:nth-child(4)
{
text-align: right;
}

Adding plus sign after "..." when using text-overflow

So I have a table with some text and I want to truncate the text after a certain length. I've achieved this using text-overflow.
.overflow {
width: 70px;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
When clicking the table cell I want the whole text to be shown (by changing the height of the row). Like this:
+------------------+ +------------------+
| Header | | Header |
+------------------+ +------------------+
| First text block | --> | First text block |
+------------------+ +------------------+
| A long text b... | | A long text |
+------------------+ | block |
^click +------------------+
I've managed to do that as well.
But I also want to place a + sign after the "..." to show the user that the cell is clickable!
+--------------------+
| Header |
+--------------------+
| First text block |
+--------------------+
| A long text b... + |
+--------------------+
How can I do this? I tried using :after but that only added the + after the whole text.
What I've got so far: http://jsfiddle.net/6qLcrswc/1/
Thanks!
You can just set position absolute on your pseudo-element :
$(".overflow").click(function() {
$(this).toggleClass("overflow");
});
table,
td {
border: 1px solid black;
}
td {
width: 70px;
}
td .overflow {
width: 70px;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
padding-right: 10px;
}
div {
position: relative;
}
div::after {
position: absolute;
content: " +";
bottom: 0;
right: 0;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table>
<tr>
<td>
<div class="overflow">A long textfield</div>
</td>
</tr>
<tr>
<td>
<div class="overflow">Another long textfield</div>
</td>
</tr>
<tr>
<td>
<div class="overflow">The third long textfield</div>
</td>
</tr>
</table>
I advise you to use cursor:pointer; to show the user that the cell is clickable.
To put "+" after that you can do that setting position:relative; to div and absolute to the ::after pseudo selector and managing with right and top.
UPDATE: Exactly like Mehdi wrote

Unexpected behaviour when with HTML Table rowspan

I am creating a dynamic table generator, and during testing, I found that the following generated HTML gives an unexpected layout in all browsers (Firefox, Chrome, IE)
<table>
<tr>
<td rowspan="2"></td>
<td></td>
</tr>
<tr>
<td rowspan="2"></td>
</tr>
<tr>
<td></td>
</tr>
</table>
I am expecting a 2x3 table, with top corner merged with the left cell in middle row, and and the middle row right cell merged with the bottom right cell but instead i ended up with a 2X2 grid
side note, even if I provided a height on the css or the row/cell attribute; doesn't change layout of the resulting table.
p/s i don't intend to use this for layouts; i just will like to idiot proof my codes from unintended effects from weird layouts such as this
Edit:
Expected:
|------|-------|
| | |
| | |
| |-------|
| | |
| | |
|------| |
| | |
| | |
|------|-------|
Result:
|------|-------|
| | |
| | |
|------|-------|
| | |
| | |
|------|-------|
Edit 2:
added CSS
table {
border: 2px solid #000000;
padding: 10px;
}
td {
border: 2px solid #FF0000;
height: 100px;
width: 100px;
padding: 10px;
}
tr {
border: 2px solid #00FF00;
padding: 10px
}
I also tried:
<table>
<tr>
<td rowspan="2" style="border: 1px solid #FF0000; height:200px"></td>
<td style="border: 1px solid #FF0000; height:100px"></td>
</tr>
<tr>
<td rowspan="2" style="border: 1px solid #FF0000; height:200px"></td>
</tr>
<tr>
<td style="border: 1px solid #FF0000; height:100px"></td>
</tr>
</table>