Summarize columns when Footable is in small devices - html

I have a table and I want to summarize some of the values in the columns when I show that table in small devices.
Lets suppose I have this table (Big Devices)
Process Good Bad Rework Total
P1 10 5 2 17
P2 5 3 2 10
Total 5 8 4 17
When I show this table in Small Devices I would like to show this
Process Good Other Total
P1 10 7 17 +
P2 5 5 10 +
Total 5 12 17 +
But I don't want to show the "Other" column in big devices (and I don't want to show the + symbol either). I want that column totally hidden.
I can't find how to achieve that. Any help will be really appreciated.

You can use CSS Media Queries.
Have a look at the snippet below (Use full-screen mode for desktop - to show bad & rework cells):
th, td {
padding: 5px 20px;
}
.visible-mob {
display: none;
background: #FF0;
}
.hidden-mob {
display: table-cell;
background: #38E8F1;
}
/* When Screen Width is >= 767px ( ~ Mobile Devices) */
#media screen and (max-width: 767px) {
.visible-mob {
display: table-cell;
}
.hidden-mob {
display: none;
}
}
<table>
<thead>
<tr>
<th>Process</th>
<th>Good</th>
<th class="hidden-mob">Bad</th>
<th class="hidden-mob">Rework</th>
<th class="visible-mob">Other</th>
<th>Total</th>
</tr>
</thead>
<tbody>
<tr>
<td>P1</td>
<td>10</td>
<td class="hidden-mob">5</td>
<td class="hidden-mob">2</td>
<td class="visible-mob">7</td>
<td>17</td>
</tr>
<tr>
<td>P2</td>
<td>5</td>
<td class="hidden-mob">3</td>
<td class="hidden-mob">2</td>
<td class="visible-mob">5</td>
<td>10</td>
</tr>
<tr>
<td>Total</td>
<td>5</td>
<td class="hidden-mob">8</td>
<td class="hidden-mob">4</td>
<td class="visible-mob">12</td>
<td>17</td>
</tr>
</tbody>
</table>
Hope this helps!

This is a ugly hack I applied to achieve temporarily what I want to do. If someone finds a better way please let me know.
HTML
<table class="table">
<thead>
<tr>
<th>Process</th>
<th>Good</th>
<th data-breakpoints="xs">Bad</th>
<th data-breakpoints="xs">Rework</th>
<th class="visible-column visible-column-sm" data-classes="visible-column visible-column-sm" data-visible="false">Other</th>
<th>Total</th>
</thead>
<tbody>
<tr>
<td>P1</td>
<td>10</td>
<td>5</td>
<td>2</td>
<td>7</td>
<td>17</td>
</tr>
<tr>
<td>P2</td>
<td>5</td>
<td>3</td>
<td>2</td>
<td>5</td>
<td>10</td>
</tr>
<tr>
<td>Total</td>
<td>5</td>
<td>8</td>
<td>4</td>
<td>12</td>
<td>17</td>
</tr>
</tbody>
</table>
CSS
.visible-column {
display: none !important;
}
#media screen and (max-width: 767px) {
.visible-column-sm {
display: table-cell !important;
}
}
At the end of the HTML
<script>
$(document).ready(function () {
$('.table').footable();
});
</script>
Here is the Fiddle
https://jsfiddle.net/oL7m7uqq/

Related

Rowspan at the end of the table is working differently

I've created a simple table using html and a bit of bootstrap, but the last rowspan doesn't work as I thought it will, here's code:
I wanted 4 red-marked cells to be one, so I've replaced first <td>group1</td> with <td rowspan="4">group1</td> and removed remaining 3 <td>group1</td> but it has messed up whole table.
Also it is placed it <div class="col-lg-7 mb-4"> div, but I've also tried without any div - the effect was the same. I'm not sure what is causing that problem, considering that the rest rowspans is working just fine.
/* I don't think CSS is needed, but just in case: */
table.table-bordered {
border: 1px solid #2f8dff!important;
box-shadow: 0px 0px 100px 0px #2f8dff;
margin-top: 20px;
text-transform: uppercase;
font-size: 12px;
color: white;
}
table.table-bordered>thead>tr>th {
border: 1px solid #2f8dff!important;
}
table.table-bordered>tbody>tr>td {
border: 1px solid #2f8dff!important;
}
<table class="table table-bordered">
<thead>
<tr>
<th></th>
<th>mon</th>
<th>tue</th>
<th>wed</th>
<th>thu</th>
<th>fri</th>
</tr>
</thead>
<tbody>
<tr>
<td rowspan="2">17:00-18:00</td>
<td>1</td>
<td>2</td>
<td>3</td>
<td>4</td>
<td>5</td>
</tr>
<tr>
<td>6</td>
<td>7</td>
<td>8</td>
<td>9</td>
<td>10</td>
</tr>
<tr>
<td rowspan="2">18:00-19:00</td>
<td>1</td>
<td rowspan="2">group3</td>
<td>3</td>
<td>4</td>
<td rowspan="2">group3</td>
</tr>
<tr>
<td rowspan="2">group2</td>
<td>8</td>
<td rowspan="2">group2</td>
</tr>
<tr>
<td rowspan="2">19:00-20:00</td>
<td rowspan="4">group1</td>
<td rowspan="2">group1</td>
<td>group1</td>
</tr>
<tr>
<td rowspan="3">group1</td>
<td rowspan="3">group1</td>
<td>group1</td>
</tr>
<tr>
<td rowspan="2">20:00-21:00</td>
<td>3</td>
<td>group1</td>
</tr>
<tr>
<td>7</td>
<td>group1</td>
</tr>
</tbody>
</table>
What shall I do?
Thanks in advance!
I don't really know what you mean by "messed up whole table". After adding the row-span="4" and removing the three following td tags, the table looked just fine for me:
The only thing I can see is the changing height of that table cell. This can be prevented by adding this CSS:
tr {
height: 1rem;
}
It makes every row equal height and produces following result:

How to control the width of - tr:nth-child(odd)

I am looking at using tr:nth-child(odd) to create a style for my datasheets. the code is below:
Now, my only real question is how do I make it so that I adjust the width? I want it to fill a space that is 200px by 400px
The depth isn't an issue since each row will dictate the depth, but the length does matter. The code I am using now only center aligns it, and I can't seem to find a way to stretch the fields. I know I am missing something, any help would be greatly appreciated.
tr:nth-child(odd) {
background: #4D4D4D}
<div class="black">
<table class="test2">
<tr>
<td>Text</td>
<td>Text2</td>
<td>Text3</td>
<td>Text4</td>
</tr>
<tr>
<td>5</td>
<td>6</td>
<td>7</td>
<td>8</td>
</tr>
<tr>
<td>9</td>
<td>10</td>
<td>11</td>
<td>13</td>
</tr>
</table>
</div>
CSS Tricks Explanation on TR widths
The only options would be to:
Increase the columns that the row takes up. This could be very fidgety
OR
Do something similar to this example here: Semantic replacement for a table
As someone who prefers semantic markup, and enjoyable websites... I would choose option 2.
HTML
body {
font: normal medium/1.4 sans-serif;
}
table {
border-collapse: collapse;
width: 100%;
}
th,
td {
padding: 0.25rem;
text-align: left;
border: 1px solid #ccc;
}
tbody tr:nth-child(odd) {
background: #4D4D4D;
}
<div class="black">
<table class="test2">
<thead>
<tr>
<th>Text</th>
<th>Text2</th>
<th>Text3</th>
<th>Text4</th>
</tr>
</thead>
<tbody>
<tr>
<td>5</td>
<td>6</td>
<td>7</td>
<td>8</td>
</tr>
<tr>
<td>9</td>
<td>10</td>
<td>11</td>
<td>12</td>
</tr>
</tbody>
</table>
</div>

Centering a column in a table

I am trying to center just certain columns in a table but I am having issues. I know in the past you would just simply apply inline styles to each TD but there has to be a better way.
Here is a simple example:
.centerText{
text-align:center;
}
<table border="1">
<col>
<col class="centerText">
<thead>
<tr>
<th>heading1</th>
<th>heading2</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>2</td>
</tr>
<tr>
<td>3</td>
<td>4</td>
</tr>
<tr>
<td>5</td>
<td>6</td>
</tr>
<tr>
<td>7</td>
<td>8</td>
</tr>
</tbody>
</table>
With that class I am trying to center the text inside. I know applying css to the col will work for changing background color for the column and text color and such, but I am not sure how I would use it to center a column. I am assuming because I need to center the contents of the td and this is probably just centering the TD element itself; which is already 100 percent.
I understand I can just say apply the css to the 5th TD in this TR but that seems fragile.
Also, bonus points if you can show me how to change the width of a column this way. I used the width attribute for col but that is deprecated in html 5 (even though it is still currently supported.
Done, your class wasn't used anywhere
tr td:nth-child(2) {
text-align:center;
}
<table border="1">
<thead>
<tr>
<th>heading1</th>
<th>heading2</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td >2</td>
</tr>
<tr>
<td>3</td>
<td>4</td>
</tr>
<tr>
<td>5</td>
<td>6</td>
</tr>
<tr>
<td>7</td>
<td>8</td>
</tr>
</tbody>
</table>
I removed:
<col>
<col class="centerText">
and
.centerText{
text-align:center;
}
Because col doesn't mean anything and you didn't close the tags.
CSS
table {
border-collapse: collapse;
width: 100%;
}
td {
text-align: center
}
If you want to align your all td content to the center
add the centerText class to your table
<table class="centerText" border="1">
It's not completely clear what you want, but if you want to center the contents of a certain column, you can just use this CSS rule:
td:nth-child(2) {
text-align:center;
}
In this example it applies to the second column, but you could define that for any column. It works since the td are always children of a tr, so you can use the nth-child selector.
td:nth-child(2) {
text-align: center;
}
<table border="1">
<col>
<col class="centerText">
<thead>
<tr>
<th>heading1</th>
<th>heading2</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>2</td>
</tr>
<tr>
<td>3</td>
<td>4</td>
</tr>
<tr>
<td>5</td>
<td>6</td>
</tr>
<tr>
<td>7</td>
<td>8</td>
</tr>
</tbody>
</table>

HTML Break Table Columns (TD) To Multiple Rows On Small Screens

I have a html table:
<table>
<tr> <td>data...</td> <td>data...</td> <td>data...</td> </tr>
</table>
This shows as:
-------------------------
|data...|data...|data...|
-------------------------
which is fine on large screens, but what i want is to break the columns into multiple rows as needed if the screen is small.
So when needed the table would show as:
----------
|data....|
|--------|
|data....|
|--------|
|data....|
----------
Is there a way to do this with something like css?
You can change to display: table-row with media queries Fiddle
#media(max-width: 480px) {
td {
display: table-row;
}
}
<table>
<tr> <td>data...</td> <td>data...</td> <td>data...</td> </tr>
</table>
You can use display:block as for break the column
#media(max-width: 480px) {
td {
display:block;
}
}
<table>
<tr> <td>data...</td> <td>data...</td> <td>data...</td> </tr>
</table>
Make the td as display block and give the width as 100%.
#media screen and (max-width:768px){
th,td { display:block; width:100%; }
}
<table>
<thead>
<tr>
<th>#</th>
<th>#</th>
<th>#</th>
<th>#</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>1</td>
<td>1</td>
<td>1</td>
</tr>
</tbody>
</table>

when changing image-size td-size won't change

I have made a table with three columns, two with text and one with a picture. The table has 10 rows, so I gave the the cell with the picture a rowspan of 10. I am able to change the width of the picture, but for some odd reason the table-cell won't change it's width. The cell still have the width, the picture originally had.
I have tried setting the image to block, but that doesn't help with the td-width. I could give the td a class with a max-width, but I am looking for another solution.
example
HTML
<table>
<thead>
<tr><th colspan="2">Attribute</th></tr>
</thead>
<tbody>
<tr>
<td>Stufe</td>
<td>9</td>
<td rowspan="10"><img src="#"></img></td>
</tr>
<tr>
<td>Vitalität</td>
<td>12</td>
</tr>
<tr>
<td>Zauberei</td>
<td>10</td>
</tr>
<tr>
<td>Kondition</td>
<td>11</td>
</tr>
<tr>
<td>Belastung</td>
<td>15</td>
</tr>
<tr>
<td>Stärke</td>
<td>13</td>
</tr>
<tr>
<td>Geschicklichkeit</td>
<td>12</td>
</tr>
<tr>
<td>Intelligenz</td>
<td>9</td>
</tr>
<tr>
<td>Glaube</td>
<td>9</td>
</tr>
<tr>
<td>Glück</td>
<td>7</td>
</tr>
</tbody>
</table>
CSS (nothing special)
table {
font-size:90%;
margin:1.5em auto;
padding:0 1em;
border-collapse:collapse;
text-align:center;}
article table thead {
background:#91414B;}
article table th, main article table td {
padding:0.25em 0.5em;}
table img {
display:block;
width:50%;}
table a {
text-decoration:underline;
color:#FFFFFF;}
table a:hover {
text-decoration:none;
color:#C6C6C6;}