Hidden Rows in Bootstrap have a height - html

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>

Related

jQuery prepend tr after tr heading

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>

How can I remove all left and right padding in an html table cell?

I am creating a timeline, with a column for each year represented in the timeline; I want these year columns to be as "skinny" (unwide) as possible. Right now they look like so:
How can I remove all the left and right padding within the cells between the years?
My current code is:
<table class="table table-sm table-bordered">
<thead class="thead-dark">
<tr>
<th scope="col">NAME</th>
<th scope="col">RELATIONSHIP</th>
<th scope="col">1794</th>
<th scope="col">1795</th>
<th scope="col">1796</th>
NOTE: I also want the rows to refrain from wrapping. The rows code is currently:
<tr>
<th scope="row">John Marshall Clemens</th>
<td>Father</td>
<td>~</td>
<td>~</td>
<td>~</td>
You can use it like this
<table cellpadding = "0">
<tr>
<th> Month </th>
<th> Savings </th>
</tr>
<tr>
<td> January </td>
<td> $100 </td>
</tr>
</table>
As you are using bootstrap you can remove any padding and margins with bootstrap spacing helper classes
It has a very flexible syntax to adding or removing paddings and margings. In your case you need to ad px-0 class to your corsponding th and td tags in head and body like bellow:
<table class="table table-bordered text-center">
<thead>
<tr>
<th>Name</th>
<th>Relation</th>
<th class="px-0">1794</th>
<th class="px-0">1795</th>
<th class="px-0">1796</th>
<th class="px-0">1797</th>
</tr>
</thead>
<tbody>
<tr>
<td>jhon</td>
<td>fater</td>
<td class="px-0">~</td>
<td class="px-0">~</td>
<td class="px-0">~</td>
<td class="px-0">~</td>
</tr>
<tr>
<td>mark</td>
<td>self</td>
<td class="px-0">~</td>
<td class="px-0">~</td>
<td class="px-0">~</td>
<td class="px-0">~</td>
</tr>
<tr>
<td>livy</td>
<td>wife</td>
<td class="px-0">~</td>
<td class="px-0">~</td>
<td class="px-0">~</td>
<td class="px-0">~</td>
</tr>
</tbody>
</table>
px-0 is equal to
.px-0 {
padding-right: 0 !important;
padding-left: 0 !important;
}
if you are using bootstrap then bootstrap itself provide padding of 12px with <td> and <th>. so for making table "skinny" you need to override css.
html
<table class="table table-bordered text-center">
<thead>
<tr>
<th>Name</th>
<th>Relation</th>
<th>1794</th>
<th>1795</th>
<th>1796</th>
<th>1797</th>
</tr>
</thead>
<tbody>
<tr>
<td>jhon</td>
<td>fater</td>
<td>~</td>
<td>~</td>
<td>~</td>
<td>~</td>
</tr>
<tr>
<td>mark</td>
<td>self</td>
<td>~</td>
<td>~</td>
<td>~</td>
<td>~</td>
</tr>
<tr>
<td>livy</td>
<td>wife</td>
<td>~</td>
<td>~</td>
<td>~</td>
<td>~</td>
</tr>
</tbody>
</table>
css
th, td {
padding: 0;
}

Nested table tag in html

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>

How do I repeat table headers per record on mobile (create a stacked view on mobile)

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>

html css code to display multiple tables horizontally or in a single row

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>