I want to have some HTML like the following:
<table>
<tbody>
<tr data-bind="foreach: foo">
<td>some header</td>
<td data-bind="value: bar"></td>
</tr>
</tbody>
</table>
I want repeated cells generated by a Knockout foreach binding. But how can I do this while having a header cell which I don't want repeated? The desired output, after binding, is something like:
<table>
<tbody>
<tr>
<td>some header</td>
<td>fred</td>
<td>wilma</td>
<td>barney</td>
<td>bam-bam</td>
</tr>
</tbody>
</table>
The same question applies to having a header row. If the foreach binding is on the <tr> element, how do I tell Knockout not to repeat the first row or cell?
You can use the containerless version of the binding ( see in the documentation: Using foreach without a container element section)
<table>
<tbody>
<tr>
<td>some header</td>
<!-- ko foreach: foo -->
<td data-bind="text: bar"></td>
<!-- /ko -->
</tr>
</tbody>
</table>
Demo JSFiddle.
So the same technique can be used if you want to have a fixed header row:
<table>
<tbody>
<tr>
<td>some header</td>
</tr>
<!-- ko foreach: foo -->
<tr>
<td data-bind="text: bar"></td>
</tr>
<!-- /ko -->
</tbody>
</table>
You can use this
<table>
<tbody>
<tr>
<td>Some header</td>
<!-- ko foreach: foo -->
<td data-bind="value: bar"></td>
<!-- /ko -->
</tr>
</tbody>
</table>
To repeat tr you can use same desicion, but it better to use html possibilities
<table>
<thead>
<tr>
<td> Header </td>
</tr>
</thead>
<tbody>
<tr data-bind="foreach: foo">
<td data-bind="text: bar"></td>
</tr>
</tbody>
</table>
Related
<div *ngFor = "let recordData of employees.record">
<div *ngIf = 'recordData.queryName==="style-size-query"'>
<table class ="table">
<thead>
<tr> product </tr>
<tr> size </tr>
<tr> sortOrder </tr>
</thead>
<tbody>
<tr>
<td> {{recordData.data.product}} </td>
<td> {{recordData.data.size}} </td>
<td> {{recordData.data.sortOrder}} </td>
</tr>
</tbody>
</table>
</div>
</div>
// **this is Angular code and this is the output this code is working but table header data is repeating after the each iteration.
I used ngFor for iteration the record array (it is in the first photo) loop. I used the ngIf to select the queryName and there are six record will come (it is in the first photo). I want that six record under a one table
**
Just moved structural directives and used ng-container to use ngIf and ngFor
I don't want to add extra element like div or span to apply ngIf and ngFor condition. that's why I used ng-container.
<div>
<div>
<table class ="table">
<thead>
<tr> product </tr>
<tr> size </tr>
<tr> sortOrder </tr>
</thead>
<tbody>
<ng-container *ngFor = "let recordData of employees.record">
<ng-container *ngIf = 'recordData.queryName==="style-size-query"'>
<tr>
<td> {{recordData.data.product}} </td>
<td> {{recordData.data.size}} </td>
<td> {{recordData.data.sortOrder}} </td>
</tr>
</ng-container>
</ng-container>
</tbody>
</table>
</div>
</div>
Please try like this
<table class ="table">
<thead>
<tr> product </tr>
<tr> size </tr>
<tr> sortOrder </tr>
</thead>
<div *ngIf = 'recordData.queryName==="style-size-query"'>
<tbody>
<tr>
<td> {{recordData.data.product}} </td>
<td> {{recordData.data.size}} </td>
<td> {{recordData.data.sortOrder}} </td>
</tr>
</tbody>
</div>
</table>
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>
I have a Flask application that takes a bunch of input from the users, processes it and generates a table/matrix of values.
I want to display this table to the user with different colors for different cells. At the time of the table generation I know what color I want the cell to be.
I am using Bootstrap4. Can this be done using Bootstrap?
The class attribute can be used in the table row to get the required colors.
<table class="table">
<thead>
<tr>
<th>Name</th>
<th>Age</th>
</tr>
</thead>
<tbody>
<tr class="active">
<td>ABC</td>
<td>10</td>
</tr>
<tr class="danger">
<td>DEF</td>
<td>20</td>
</tr>
<tr class="info">
<td>GHI</td>
<td>30</td>
</tr>
<tr class="success">
<td>JKL</td>
<td>40</td>
</tr>
<tr class="warning">
<td>MNO</td>
<td>50</td>
</tr>
</tbody>
</table>
In Bootstrap 4, you can give color to the table rows by adding bg classes to the <tr> elements like;
<tr class="bg-success">...</tr>
<tr class="bg-warning">...</tr>
<tr class="bg-danger">...</tr>
Take a look at bootstrap documentation of tables which explains it in detail
This is the way to add color on cells
<!doctype html>
<html lang="en">
<head>
<title>Table Color</title>
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css">
<!-- jQuery library -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.0/jquery.min.js"></script>
<!-- Popper JS -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js"></script>
<!-- Latest compiled JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container">
<table class="table">
<thead>
<tr>
<th>Firstname</th>
<th>Lastname</th>
<th>Email</th>
</tr>
</thead>
<tbody class="table-hover">
<tr>
<td>Default</td>
<td>Defaultson</td>
<td>def#somemail.com</td>
</tr>
<tr class="table-primary">
<td>Primary</td>
<td>Joe</td>
<td>joe#example.com</td>
</tr>
<tr class="table-success">
<td>Success</td>
<td>Doe</td>
<td>john#example.com</td>
</tr>
<tr class="table-danger">
<td>Danger</td>
<td>Moe</td>
<td>mary#example.com</td>
</tr>
<tr class="table-info">
<td>Info</td>
<td>Dooley</td>
<td>july#example.com</td>
</tr>
<tr class="table-warning">
<td>Warning</td>
<td>Refs</td>
<td>bo#example.com</td>
</tr>
<tr class="table-active">
<td>Active</td>
<td>Activeson</td>
<td>act#example.com</td>
</tr>
<tr class="table-secondary">
<td>Secondary</td>
<td>Secondson</td>
<td>sec#example.com</td>
</tr>
<tr class="table-light">
<td>Light</td>
<td>Angie</td>
<td>angie#example.com</td>
</tr>
<tr class="table-dark text-dark">
<td>Dark</td>
<td>Bo</td>
<td>bo#example.com</td>
</tr>
</tbody>
</table>
</div>
</body>
</html>
More about table
table documentation bootstrap 4
I need something like this:
<tr>
somecode...
</tr *ngIf="some condition">
which of course isn't supported, but is there any way to achieve this behavior?
I have a table, and I want to add rows to it recursively using a component that receives node's list(List), iterates over the nodes, print them and calls itself for each of the children of each node roughly like this:
main.component.html
<table class="table table-bordered">
<thead>
<tr>
<th>node names</th>
</tr>
</thead>
<tbody>
<tr app-rower [nodes]="nodes"></tr>
</tbody>
</table>
rower.component.html:
<ng-container *ngFor="let node of tree">
<tr>
<td>
{{node.name}}
</td>
</tr *ngIf="node.hasChildren">
<tr *ngIf="node.hasChildren" app-rower [tree]="node.children" >
</tr *ngIf="!node.hasChildren">
</ng-container>
so a final html would be:
<table>
<thead>
<tr>
<th>node's names</th>
</tr>
</thead>
<tbody>
<tr>
<td>node 1</td>
</tr>
<tr>
<td>node 1's child</td>
</tr>
<tr>
<td>node 1's grandchild</td>
</tr>
<tr>
<td>node 2</td>
</tr>
<tr>
<td>node 2's child</td>
</tr>
</tbody>
</table>
No, that's not supported. A template needs to be valid HTML otherwise Angular won't parse it.
<ng-container *ngFor="let node of tree">
<tr>
<td>
{{node.name}}
</td>
</tr>
<tr *ngIf="node.hasChildren" app-rower [tree]="node.children" >
</tr>
</ng-container>
I have few rows in table that contain 10 co-morbidities.
<table>
<!-- Co-Morbidities1 -->
<tr id="como1">
<td>Row1 </td>
<td>Co-Morbidities1 </td>
<td>value column</td>
</tr>
<!-- Co-Morbidities2 -->
<tr id="como2">
<td>Row2 </td>
<td>Co-Morbidities2 </td>
<td> </td>
</tr>
<!-- Co-Morbidities3 -->
<tr id="como13">
<td>Row3 </td>
<td>Co-Morbidities3 </td>
<td> </td>
</tr>
<!-- Co-Morbidities4 -->
<tr id="como4">
<td>Row4 </td>
<td>Co-Morbidities4 </td>
<td> </td>
</tr>
<!-- Co-Morbidities5 -->
<tr id="como5">
<td>Row5 </td>
<td>Co-Morbidities5 </td>
<td> </td>
</tr>
<!-- Co-Morbidities6 -->
<tr id="como6">
<td>Row6 </td>
<td>Co-Morbidities6 </td>
<td> </td>
</tr>
<!-- Co-Morbidities7 -->
<tr id="como7">
<td>Row7 </td>
<td>Co-Morbidities7 </td>
<td> </td>
</tr>
<!-- Co-Morbidities8 -->
<tr id="como8">
<td>Row8 </td>
<td>Co-Morbidities8 </td>
<td> </td>
</tr>
<!-- Co-Morbidities9 -->
<tr id="como9">
<td>Row9 </td>
<td>Co-Morbidities9 </td>
<td> </td>
</tr>
<!-- Co-Morbidities10 -->
<tr id="como10">
<td>Row10 </td>
<td>Co-Morbidities10 </td>
<td> </td>
</tr></table>
What I want to achieve is, I don't want to display the 10 rows all at once, but display them one at a time. If the first row value is populated, then I want the second row to be displayed, if the second row value is populated, then I want the third row to be displayed, and so on. I want the rows to be displayed progressively based on the values in the previous row is populated.
I am new to Javascript, just beginning to learn. I did spent hours on Google and found no joy. Please could someone help? Much appreciated.
Simple example http://jsfiddle.net/tJdFZ/
Using jquery
This line hides all of the rows in the table $('table tr').hide();
then I show the first line $('table tr:eq(0)').show(); The eq selector selects the element based on the number, 0 being the first row, 1 being the second, etc.
Then I just use the button click, I add 1 to the current row, and show that row. You could use the same idea to hide one row at a time, or you could make a button to show all rows, etc.
EDIT
I created another function that hides a row http://jsfiddle.net/tJdFZ/1/
EDIT
Alright, last try. by adding a class to the "tr" you can have rows that are controlled by the buttons, and rows that are static. Take a look at the new fiddle http://jsfiddle.net/tJdFZ/24/
HTML
<table>
<tr>
<td colspan=3>Static Row</td>
</tr>
<tr>
<td colspan=3>Static Row</td>
</tr>
<tr>
<td colspan=3>Static Row</td>
</tr>
<!-- Co-Morbidities1 -->
<tr id="como1" class="showhide">
<td>Row1 </td>
<td>Co-Morbidities1 </td>
<td>value column</td>
</tr>
<!-- Co-Morbidities2 -->
<tr id="como2" class="showhide">
<td>Row2 </td>
<td>Co-Morbidities2 </td>
<td> </td>
</tr>
<!-- Co-Morbidities3 -->
<tr id="como3" class="showhide">
<td>Row3 </td>
<td>Co-Morbidities3 </td>
<td> </td>
</tr>
<!-- Co-Morbidities4 -->
<tr id="como4" class="showhide">
<td>Row4 </td>
<td>Co-Morbidities4 </td>
<td> </td>
</tr>
<!-- Co-Morbidities5 -->
<tr id="como5" class="showhide">
<td>Row5 </td>
<td>Co-Morbidities5 </td>
<td> </td>
</tr>
<!-- Co-Morbidities6 -->
<tr id="como6" class="showhide">
<td>Row6 </td>
<td>Co-Morbidities6 </td>
<td> </td>
</tr>
<!-- Co-Morbidities7 -->
<tr id="como7" class="showhide">
<td>Row7 </td>
<td>Co-Morbidities7 </td>
<td> </td>
</tr>
<!-- Co-Morbidities8 -->
<tr id="como8" class="showhide">
<td>Row8 </td>
<td>Co-Morbidities8 </td>
<td> </td>
</tr>
<!-- Co-Morbidities9 -->
<tr id="como9" class="showhide">
<td>Row9 </td>
<td>Co-Morbidities9 </td>
<td> </td>
</tr>
<!-- Co-Morbidities10 -->
<tr id="como10" class="showhide">
<td>Row10 </td>
<td>Co-Morbidities10 </td>
<td> </td>
</tr></table>
<input type=button value="Show 1 more" id="onemore" />
<input type=button value="Hide 1" id="oneless" />
JQUERY
var currentrow = 0;
var maxrows = $('.showhide').size() - 1;
$('table tr.showhide').hide();
$('table tr.showhide:eq(0)').show();
$("#onemore").click(function() {
if (currentrow < maxrows) {
currentrow++;
$('table tr.showhide:eq(' + currentrow + ')').show();
}
});
$("#oneless").click(function() {
if (currentrow > 0) {
$('table tr.showhide:eq(' + currentrow + ')').hide();
currentrow--;
}
});