I'm trying to display a child table whenever user clicks on the parent cell. here is my code snippet.it is working only for the first row after that from the second record it is not loading the data in a table. (displaying plain data) any help that would be great. Thanks!
<table class="table table-borderless table-hover">
<thead>
<tr>
<th> </th>
<th scope="col">student.Id</th>
.............
</tr>
</thead>
<tbody>
#foreach($data as $student)
<tr class="clickable" data-toggle="collapse" id="row{{ $student['id'] }}" data-target=".row{{ $student['id'] }}">
<td>{{ $student['id'] }}</td>
</tr>
#if ($student['subjects'])
<tr>
<td colspan="3">
<table class="table table-sm table-dark collapse row{{ $student['id'] }}">
<thead>
<tr>
<th scope="col">subject.Id</th>
..............
</tr>
</thead>
<tbody>
#foreach($student['subjects'] as $subject)
<tr>
<td>{{$subject['id']}}</td>
</tr>
#endforeach
</tbody>
</table>
</td>
</tr>
#endif
#endforeach
</tbody>
</table>
Your basic table semantics is wrong. To have nested table, the child tableshould go inside a <td>
table,
th,
td {
border: 1px solid black;
}
<table style="width:100%">
<tr>
<th>Firstname</th>
<th>Lastname</th>
<th>Age</th>
</tr>
<tr>
<td>Jill</td>
<td>Smith</td>
<td>50</td>
</tr>
<tr>
<td colspan="3">
<table style="width:100%">
<tr>
<th>Firstname</th>
<th>Lastname</th>
<th>Age</th>
</tr>
<tr>
<td>Jill</td>
<td>Smith</td>
<td>50</td>
</tr>
</table>
</td>
</tr>
</table>
Related
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.
I have the following HTML table.
<table id="table">
<tbody>
<tr>
<th>City</th>
</tr>
<tr>
<td>Madrid</td>
</tr>
<tr class="show-on-top">
<td data-order="3">London</td>
</tr>
<tr>
<td>Berlin</td>
</tr>
<tr>
<td data-order="1">Paris</td>
</tr>
<tr class="show-on-top">
<td data-order="2">Rome</td>
</tr>
</tbody>
London, Paris and Rome have a class named show-on-top. As the name suggests I want to move all tr with show-on-top on top of the table. I can do that with the following code.
$("#table tbody").prepend($('.show-on-top'));
But the problem is that London, Paris and Rome are shown before <th> (the "City" heading). Of course I want to place show-on-top rows on top of the table but after heading (first row). So I came up with the following idea.
$("#table tbody tr:eq(1)").prepend($('.show-on-top'));
I'm almost there. All my show-on-top are placed after heading but they're nested inside a tr like follows.
<table id="table">
<tbody>
<tr>
<th>City</th>
</tr>
<tr>
<tr class="show-on-top">
<td data-order="3">London</td>
</tr>
<tr>
<td data-order="1">Paris</td>
</tr>
<tr class="show-on-top">
<td data-order="2">Rome</td>
</tr>
</tr>
<tr>
<td>Madrid</td>
</tr>
<tr>
<td>Berlin</td>
</tr>
</tbody>
I can't understand how the heck all my rows are nested inside a tr. I'm tried with hundreds of combinations of parent, after, prepend, append with no success.
Bonus question. show-on-top rows have data-order attribute that represents the order I want to sort th rows in question (Paris > Rome > London). I used sort.data('order') but nothing happens. I can't even see anything in console.log().
Thank you for your time.
One thing you can do is move the heading rows out of <tbody> into <thead>
$("#table tbody").prepend($('.show-on-top'));
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<table id="table">
<thead>
<tr>
<th>City</th>
</tr>
</thead>
<tbody>
<tr>
<td>Madrid</td>
</tr>
<tr class="show-on-top">
<td data-order="3">London</td>
</tr>
<tr>
<td>Berlin</td>
</tr>
<tr>
<td data-order="1">Paris</td>
</tr>
<tr class="show-on-top">
<td data-order="2">Rome</td>
</tr>
</tbody>
</table>
Another solution is to use .after() to put the rows after the last row containing th.
$("#table tbody tr:has(th):last").after($(".show-on-top"));
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<table id="table">
<tbody>
<tr>
<th>City</th>
</tr>
<tr>
<td>Madrid</td>
</tr>
<tr class="show-on-top">
<td data-order="3">London</td>
</tr>
<tr>
<td>Berlin</td>
</tr>
<tr>
<td data-order="1">Paris</td>
</tr>
<tr class="show-on-top">
<td data-order="2">Rome</td>
</tr>
</tbody>
</table>
You could use insertAfter() and :first selector
$(".show-on-top").insertAfter('#table tbody tr:first');
.show-on-top{ color:red}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<table id="table">
<tbody>
<tr>
<th>City</th>
</tr>
<tr>
<td>Madrid</td>
</tr>
<tr class="show-on-top">
<td data-order="3">London</td>
</tr>
<tr>
<td>Berlin</td>
</tr>
<tr>
<td data-order="1">Paris</td>
</tr>
<tr class="show-on-top">
<td data-order="2">Rome</td>
</tr>
</tbody>
</table>
Sure this has a simple answer but can't get my head around it.
I have bootstrap table that has hidden rows that display on click of the row that it's hidden behind. However, the hidden rows show up and I can't get them to disappear when they're not selected.
Trying to get rid of the highlighted space between rows as per this pic:
<table class='table table-hover table-bordered table-striped'>
<thead>
<tr>
<th>Status</th>
<th>Name</th>
<th>GuideWire</th>
</tr>
</thead>
<tbody>
<tr data-toggle='collapse' data-target='#info_1'>
<td>Good</td>
<td>FooBar</td>
<td>Something else</td>
</tr>
<tr>
<td colspan='8' class='hidden-row'>
<div class='collapse' id='info_1'>
<table class="table table-condensed table-sm small">
<thead>
<th>ABC</th>
<th>DEF</th>
</thead>
<tbody>
<tr>
<td>S1</td>
<td>Blah</td>
</tr>
<tr>
<td>S1</td>
<td>Blah</td>
</tr>
</tbody>
</table>
</div>
</td>
</tr>
<tr data-toggle='collapse' data-target='#info_2'>
<td>Good 2</td>
<td>FooBar 2</td>
<td>Something else 2</td>
</tr>
<tr>
<td colspan='8' class='hidden-row'>
<div class='collapse' id='info_2'>
<table class="table table-condensed table-sm small">
<thead>
<th>ABC</th>
<th>DEF</th>
</thead>
<tbody>
<tr>
<td>S1</td>
<td>Blah</td>
</tr>
<tr>
<td>S1</td>
<td>Blah</td>
</tr>
</tbody>
</table>
</div>
</td>
</tr>
</tbody>
</table>
If you know how to get .table-striped to ignore hidden rows too, that'd be great.
It's the top & bottom padding. You can reset it with..
.table>tbody .hidden-row {
padding: 0 8px;
}
http://www.codeply.com/go/Ev7XStMM0f
This way it's only adjusting the hidden-row, and not overriding the Bootstrap table defaults. Also, you probably want to keep the left/right padding so the columns in the hidden-row align properly.
Its the padding which is giving it the space.
This should work
.table>tbody>tr>td.hidden-row, .table>tbody>tr>th.hidden-row,
.table>tfoot>tr>td.hidden-row,
.table>tfoot>tr>th.hidden-row, .table>thead>tr>td.hidden-row,
.table>thead>tr>th.hidden-row {
padding: 0;
}
Reset the css properties
.table.table-hover {
line-height: 0;
height: 0px;
padding: 0;
}
Try the below code and let me know if it works for you
**CSS**
.inner-table-data
{
margin-bottom: 0;
}
**HTML**
<table class='table table-hover table-bordered table-striped'>
<thead>
<tr>
<th>Status</th>
<th>Name</th>
<th>GuideWire</th>
</tr>
</thead>
<tbody>
<tr data-toggle='collapse' data-target='#info_1'>
<td class="col-sm-4">Good</td>
<td class="col-sm-4">FooBar</td>
<td class="col-sm-4">Something else</td>
</tr>
<tr>
<td colspan='1' class='collapse' id='info_1'>
<div>
<table class="table table-striped inner-table-data">
<thead>
<th>ABC</th>
<th>DEF</th>
</thead>
<tbody>
<tr>
<td>S1</td>
<td>Blah</td>
</tr>
<tr>
<td>S1</td>
<td>Blah</td>
</tr>
</tbody>
</table>
</div>
</td>
</tr>
<tr data-toggle='collapse' data-target='#info_2'>
<td class="col-sm-4">Good 2</td>
<td class="col-sm-4">FooBar 2</td>
<td class="col-sm-4">Something else 2</td>
</tr>
<tr>
<td colspan='1' class='collapse' id='info_2'>
<div>
<table class="table table-striped inner-table-data">
<thead>
<th>ABC</th>
<th>DEF</th>
</thead>
<tbody>
<tr>
<td>S1</td>
<td>Blah</td>
</tr>
<tr>
<td>S1</td>
<td>Blah</td>
</tr>
</tbody>
</table>
</div>
</td>
</tr>
</tbody>
</table>
I'm new to bootstrap. I'm using bootstrap 3. I'm trying to figure out how I can create the following so that it looks like a standard table when not viewing it on a mobile device, and in a more stacked fashion when on mobile.
This is what I'm wanting to do:
You need to your code mention in two different table. & then use css class .hidden-xs & .visible-xs for show & hide in responsive and non-responsive view.
Example following code. also, check it here in jsfiddle
<!--Non-Mobile-->
<table class="table table-bordered table-hover hidden-xs">
<thead>
<tr>
<td>DOMAIN</td>
<td>USER</td>
<td>ACCT</td>
<td>STATUS</td>
<td>ACTIONS</td>
</tr>
</thead>
<tbody>
<tr>
<td>domain1.co</td>
<td>user1</td>
<td>123456</td>
<td>active</td>
<td>edit</td>
</tr>
<tr>
<td>domain2.co</td>
<td>user1</td>
<td>654321</td>
<td>active</td>
<td>edit</td>
</tr>
</tbody>
</table>
<!--Responsive-->
<table class="table table-bordered table-hover visible-xs">
<tr>
<td>DOMAIN</td>
</tr>
<tr>
<td>domain1.co</td>
</tr>
<tr>
<td>USER</td>
</tr>
<tr>
<td>user1</td>
</tr>
<tr>
<td>ACCT</td>
</tr>
<tr>
<td>123456</td>
</tr>
<tr>
<td>STATUS</td>
</tr>
<tr>
<td>active</td>
</tr>
<tr>
<td>ACTIONS</td>
</tr>
<tr>
<td>edit</td>
</tr>
</table>
<table class="table table-bordered table-hover visible-xs">
<tr>
<td>DOMAIN</td>
</tr>
<tr>
<td>domain2.co</td>
</tr>
<tr>
<td>USER</td>
</tr>
<tr>
<td>user1</td>
</tr>
<tr>
<td>ACCT</td>
</tr>
<tr>
<td>654321</td>
</tr>
<tr>
<td>STATUS</td>
</tr>
<tr>
<td>active</td>
</tr>
<tr>
<td>ACTIONS</td>
</tr>
<tr>
<td>edit</td>
</tr>
</table>
</div>
I have created a table which loops from a database. Now I need to display this multiple table in a single row. Currently the loop display tables in columns. Please can someone suggest how to write the markup, so that it generates and displays table data in a single row?
For example, if there are 10 tables loops from the database, then there should be 10 cells in a single table row. The table should not contain anything below that row. It's ok for a horizontal scrollbar to display in the event that the table is longer than the screen width.
<table width="100%" class="table table-bordered table-striped">
<table>
<thead>
<tr>
<th colspan="2">First Name</th>
</tr>
</thead>
<tbody>
<tr>
<td colspan="2">James</td>
</tr>
<tr>
<td>The</td>
<td>Tick</td>
</tr>
</tbody>
</table>
Table inside table is not valid. You have to add table row then add all the tables under each table columns like below.
<table width="100%" class="table table-bordered table-striped">
<tr>
<td>
<table>
<thead>
<tr>
<th colspan="2">First Name</th>
</tr>
</thead>
<tbody>
<tr>
<td colspan="2">James</td>
</tr>
<tr>
<td>The</td>
<td>Tick</td>
</tr>
</tbody>
</table>
</td>
<td>
Your Second Table Goes here..
</td>
<td>
Your Third Table Goes here and so on.
</td>
</tr>
</table>
If I understand you right, you want the table shown above to be repeated multiple times such and to appear side by side in a single row.
What I would do is add the CSS property display: inline-table (use a class) to the relevant tables.
See the following example:
.tablePanel {
width: 300%;
word-break: nowrap;
border: 1px dotted blue;
}
.tablePanel table {
border: 1px dashed gray;
display: inline-table;
width: 200px;
}
<div class="tablePanel">
<table>
<thead>
<tr>
<th colspan="2">First Name</th>
</tr>
</thead>
<tbody>
<tr>
<td colspan="2">James</td>
</tr>
<tr>
<td>The</td>
<td>Tick</td>
</tr>
</tbody>
</table>
<table>
<thead>
<tr>
<th colspan="2">First Name</th>
</tr>
</thead>
<tbody>
<tr>
<td colspan="2">James</td>
</tr>
<tr>
<td>The</td>
<td>Tick</td>
</tr>
</tbody>
</table> <table>
<thead>
<tr>
<th colspan="2">First Name</th>
</tr>
</thead>
<tbody>
<tr>
<td colspan="2">James</td>
</tr>
<tr>
<td>The</td>
<td>Tick</td>
</tr>
</tbody>
</table> <table>
<thead>
<tr>
<th colspan="2">First Name</th>
</tr>
</thead>
<tbody>
<tr>
<td colspan="2">James</td>
</tr>
<tr>
<td>The</td>
<td>Tick</td>
</tr>
</tbody>
</table>
</div>