CSS Table Column Freeze - html

Could someone help with this
http://jsfiddle.net/smilepak/8qRQB/4/
<div>
<table>
<tr>
<td class="headcol">Fiddle Options</td>
<td class="long">Created and maintained by Piotr and Oskar. Hosted by DigitalOcean. Special thanks to MooTools community.</td>
<td class="long">QWERTYUIOPASDFGHJKLZXCVBNM</td>
</tr>
<tr>
<td class="headcol">Legal, Credits and Links</td>
<td class="long" style="width:300px">QWERTYUIOPASDFGHJKLZXCVBNM</td>
<td class="long" style="width:300px">QWERTYUIOPASDFGHJKLZXCVBNM</td>
</tr>
<tr>
<td class="headcol">Ajax Requests</td>
<td class="long">QWERTYUIOPASDFGHJKLZXCVBNM</td>
<td class="long">QWERTYUIOPASDFGHJKLZXCVBNM</td>
</tr>
</table>
table {
border-collapse:separate;
border-top: 1px solid grey;
}
td {
margin:0;
border:1px solid grey;
border-top-width:0px;
}
div {
width: 600px;
overflow-x:scroll;
margin-left:10em;
overflow-y:visible;
padding-bottom:1px;
}
.headcol {
position:absolute;
width:10em;
left:0;
top:auto;
border-right: 1px none black;
border-top-width:1px;
/*only relevant for first row*/
margin-top:-3px;
/*compensate for top border*/
}
In firefox, the row border doesn't seem to line up. I want a table where the first column is frozen while the rest is scrollable. All rows are linked up to a single scroll bar so i can use in a loop via Razor view in MVC.
Thanks,

JSBIN: http://jsbin.com/IwisANaX/3/edit
CSS
...
.freeze td:nth-child(1),
.freeze th:nth-child(1) {
background: #ddd;
position: absolute;
width: 20px;
left: 0;
}
.freeze .bottomScroll {
overflow-x: hidden;
margin-left: 20px;
}
...
JS
var ns = $('.newScroll', table),
bs = $('.bottomScroll', table);
ns.scroll(function(){bs.scrollLeft(ns.scrollLeft());});

try using
.headcol {max-width: 10em}
also note that using
.headcol {position: absolute}
makes the cell not to align relatively to the document; thatΒ΄s why it looks like that

I used this combination of JavaScript and CSS to solve the sticky column issue.
https://jsfiddle.net/5poxyje4/
JS (Commented Section has boostrap compatible code)
var $table = $('.table');
var $fixedColumn = $table.clone().insertBefore($table).addClass('fixed-column');
$fixedColumn.find('th:not(:first-child),td:not(:first-child),.excludeHeader').remove();
$fixedColumn.find('tr').each(function (i, elem) {
if(elem.rowSpan = "1"){
$(this).height($table.find('tr:eq(' + i + ')').height());
}
else{
for (x = i; x <= parseInt(elem.rowSpan); x++) {
var tempHeight = $(this).height() + $table.find('tr:eq(' + x + ')').height();
$(this).height(tempHeight);
}
}
});
//Comments for if you are using bootrap tables
//var $table = $('.table');
//var $fixedColumn = $table.clone().insertBefore($table).addClass('fixed-column');
//$fixedColumn.find('th:not(:first-child),td:not(:first-child),.excludeHeader').remove();
//$fixedColumn.find('tr').each(function (i, elem) {
// $fixedColumn.find('tr:eq(' + i + ') > th:first-child,tr:eq(' + i + ') > td:first-child').each(function (c, cell) {
// if (cell.rowSpan == "1") {
// $(this).height($table.find('tr:eq(' + i + '),tr:not(.excludeRow)').height());
// }
// else {
// for (x = 1; x < parseInt(cell.rowSpan) ; x++) {
// var tempHeight = $(this).height() + $table.find('tr:eq(' + x + ')').height();
// $(this).height(tempHeight);
// }
// }
// $(this).width($table.find('.stickyColumn').first().width());
// });
//});
CSS(Commented section has bootstrap compatible code in my Site.css)
.table-responsive>.fixed-column {
position: absolute;
display: inline-block;
width: auto;
border-right: 1px solid #ddd;
/* used z-index with bootstrap */
/*z-index: 9999;*/
}
/*This media query conflicted with my bootstrap container. I did not use it*/
#media(min-width:768px) {
.table-responsive>.fixed-column {
display: none;
}
}
/*Commented Section for if you are using bootstrap*/
/*.table-responsive>.fixed-column {
position: absolute;
display: inline-block;
width: auto;
border-right: 1px solid #ddd;
background-color:#ffffff;
}*/
This accounts for if a th or a td has a rowspan greater than 1 as well.

Related

Table toggle not working in Safari... works fine in Chrome

I have a simple table that also has a td that is offset and acts as a toggle. It switches between 3 states and is working fine in Chrome. Can anyone help me and explain why it does not currently work in Safari, I have not tested this in other browsers yet, but would like solution to work in other browsers too.
Pic and code attached.
Thank you for any help and solutions.
M.
highlight {
background-color: #86C440;
color: white;
}
th {
font-size: 30px;
}
tr {
text-align: left;
}
td {
font-size: 20px;
background-color: #d4d6d3;
cursor: pointer;
}
.center {
margin-left: auto;
margin-right: auto;
}
tr {
position:relative;
transform:scale(1,1);
}
td.last{
position:fixed;
border: 5px solid #d4d6d3;
background-color: #4eafef;
left: -46px;
top: -46px;
height: 7px;
width: 7px;
line-height: 7px;
cursor: pointer;
}
<html>
<body>
<div id="switch">1</div>
<br><br><br><br><br><br><br><br>
<style>
table {border-collapse: collapse; border: 5px solid white; padding: 5px;}
table td {text-align: center; color: black; border: 5px solid white; padding: 10px; height: 66px; width: 66px;}
</style>
<table class="center">
<tr>
<td>1</td>
<td>2</td>
<td id="toggle" class="last" onclick="toggle1()"></td>
</tr>
<tr>
<td>3</td>
<td>4</td>
</tr>
<tr>
<td>5</td>
<td>6</td>
</tr>
</table>
</body>
<script>
function toggle1() {
var key = document.getElementById("switch").innerHTML;
if (key == 1) {
document.getElementById("toggle").style.backgroundColor = "white";
document.getElementById("toggle").style.backgroundImage = "url('')";
document.getElementById("toggle").style.borderStyle = "solid";
document.getElementById("toggle").style.borderColor = "#d4d6d3";
document.getElementById("toggle").style.borderWidth = "5px";
document.getElementById("switch").innerHTML = 2;
//console.log("toggle clicked 1st time!");
} else if (key == 2) {
document.getElementById("toggle").style.backgroundColor = "#a370f0";
document.getElementById("toggle").style.backgroundImage = "url('')";
document.getElementById("toggle").style.borderStyle = "solid";
document.getElementById("toggle").style.borderColor = "#d4d6d3";
document.getElementById("toggle").style.borderWidth = "5px";
document.getElementById("switch").innerHTML = 3;
//console.log("toggle clicked 2nd time!");
} else if (key == 3) {
document.getElementById("toggle").style.backgroundColor = "#4eafef";
document.getElementById("toggle").style.backgroundImage = "url('')";
document.getElementById("toggle").style.borderStyle = "solid";
document.getElementById("toggle").style.borderColor = "#d4d6d3";
document.getElementById("toggle").style.borderWidth = "5px";
document.getElementById("switch").innerHTML = 1;
//console.log("toggle clicked 3rd time!");
}
}
</script>
</html>
There are a few problems which seem to result in Chrome/Edge behaving differently from Safari.
There is a style declaration within the body rather than the head element. This is picked up by an HTML validator as illegal HTML. The snippet below moves it to the head.
There is a setting for tr elements which implements a transform. This seems to encourage Chrome to position the fixed element relative to the table start rather than relative to the viewport. I don't have a full explanation for this other than to note that any sort of transform seems to result in this behaviour and that any transform will create a new stacking context.
There is a 3rd cell in the first row but not in the subsequent rows. This is picked up as a warning by the validator. I do not know how the table's layout is supposed to look in this circumstance, but of course the result is complicated by the fixed setting which takes the 3rd cell out of the flow visually.
This snippet takes the 3rd cell out and puts a button before the table instead. Together with the other changes Safari and Chrome/Edge now behave the same, with Safari doing the expected behavior on border-collapse.
The button's position needs working on - perhaps the button plus table should be in a container which gets positioned? It depends on exactly what is required in terms of fixing its position.
<!doctype html>
<html>
<head>
<style>
highlight {
background-color: #86C440;
color: white;
}
th {
font-size: 30px;
}
tr {
text-align: left;
}
td {
font-size: 20px;
background-color: #d4d6d3;
cursor: pointer;
}
.center {
margin-left: auto;
margin-right: auto;
}
/* REMOVED
tr {
position:relative;
transform:scale(1, 1);
}
*/
#toggle {
position: fixed;
border: 5px solid #d4d6d3;
background-color: #4eafef;
/* REMOVED
left: -46px;
top: -46px;
*/
/* values changed */
height: 30px;
width: 30px;
rline-height: 7px;
cursor: pointer;
}
</style>
<!-- MOVED FROM body -->
<style>
table {
border-collapse: collapse;
border: 5px solid white;
padding: 5px;
}
table td {
text-align: center;
color: black;
border: 5px solid white;
padding: 10px;
height: 66px;
width: 66px;
}
</style>
</head>
<body>
<div id="switch">1</div>
<br><br><br><br><br><br><br><br>
<div class="container">
<button id="toggle" class="last" onclick="toggle1()"></button>
<table class="center">
<tbody>
<tr>
<td>1</td>
<td>2</td>
<!-- td last removed -->
</tr>
<tr>
<td>3</td>
<td>4</td>
</tr>
<tr>
<td>5</td>
<td>6</td>
</tr>
</tbody>
</table>
</div>
<script>
function toggle1() {
var key = document.getElementById("switch").innerHTML;
if (key == 1) {
document.getElementById("toggle").style.backgroundColor = "white";
document.getElementById("toggle").style.backgroundImage = "url('')";
document.getElementById("toggle").style.borderStyle = "solid";
document.getElementById("toggle").style.borderColor = "#d4d6d3";
document.getElementById("toggle").style.borderWidth = "5px";
document.getElementById("switch").innerHTML = 2;
//console.log("toggle clicked 1st time!");
} else if (key == 2) {
document.getElementById("toggle").style.backgroundColor = "#a370f0";
document.getElementById("toggle").style.backgroundImage = "url('')";
document.getElementById("toggle").style.borderStyle = "solid";
document.getElementById("toggle").style.borderColor = "#d4d6d3";
document.getElementById("toggle").style.borderWidth = "5px";
document.getElementById("switch").innerHTML = 3;
//console.log("toggle clicked 2nd time!");
} else if (key == 3) {
document.getElementById("toggle").style.backgroundColor = "#4eafef";
document.getElementById("toggle").style.backgroundImage = "url('')";
document.getElementById("toggle").style.borderStyle = "solid";
document.getElementById("toggle").style.borderColor = "#d4d6d3";
document.getElementById("toggle").style.borderWidth = "5px";
document.getElementById("switch").innerHTML = 1;
//console.log("toggle clicked 3rd time!");
}
}
</script>
<script type="text/javascript">
</script>
</body>
</html>

Cannot remove padding in table

I am trying to remove the padding from the cells inside my table. I have set it to not have padding in the relevant CSS selectors but not a success.
As you can see, there is padding on all of these cells.
I would like there to not be. I have tried various different padding settings and changing the vertical alignment makes no difference other than to move the text, the padding just goes from all at the bottom to spread between bottom and top.
Below is the code:
'use strict'
let table = document.getElementById("mainTable")
let rows = table.querySelectorAll("tbody tr")
let columns = table.querySelectorAll("#weeks th")
for (let row of rows) {
for (let o = 0; o<columns.length-1; o++) {
let cell = document.createElement("td")
cell.innerHTML='&nbsp'
cell.addEventListener("click", function() {
if (cell.getElementsByTagName("input")[0]) { return } //If cell currently has an input box
//
let oldValue = ""
if (cell.innerHTML !== " ") { //if cell has a saved value
oldValue = cell.innerHTML
}
cell.innerHTML = '<input type="text" class="cellInputs">'
//update input box with old value and focus it
cell.getElementsByTagName("input")[0].focus()
cell.getElementsByTagName("input")[0].value = oldValue
cell.getElementsByTagName("input")[0].addEventListener("keypress", function(e) {
if (e.keyCode === 13) {
cell.innerHTML=cell.getElementsByTagName("input")[0].value
e.preventDefault()
return true
}
})
cell.getElementsByTagName("input")[0].addEventListener("input", function(e) {
console.log(e)
let cellValue = cell.getElementsByTagName("input")[0].value
if (e.data === "." && (cellValue.split('.').length-1 > 1 || cellValue === ".")) {
console.log("stop")
cell.getElementsByTagName("input")[0].value = (cellValue).substring(0, cellValue.length - e.data.length)
}
if (isNaN(e.data) && e.data !==".") {
console.log("Stop")
cell.getElementsByTagName("input")[0].value = (cellValue).substring(0, cellValue.length - e.data.length)
}
//store value inputted into the actual cell
})
cell.getElementsByTagName("input")[0].addEventListener("paste", function(e) {
// clipboardData = e.clipboardData || window.clipboardData;
// pastedData = clipboardData.getData('Text');
let cellValue = cell.getElementsByTagName("input")[0].value
if (cellValue !== "") {
e.preventDefault()
return false
}
if (e.clipboardData.getData('text') === "." && (cellValue.split('.').length-1 > 1 || cellValue === ".")) {
e.preventDefault()
return false
}
if (isNaN(e.clipboardData.getData('text')) && e.clipboardData.getData('text') !==".") {
e.preventDefault()
return false
}
//store value inputted into the actual cell
})
cell.getElementsByTagName("input")[0].addEventListener("focusout", function() {
console.log(document.activeElement)
cell.innerHTML=cell.getElementsByTagName("input")[0].value
})
})
row.appendChild(cell)
}
}
*{
padding: 0;
margin: 0;
font-family: "Trebuchet MS", Times, serif;
box-sizing:border-box;
}
html{
background-color: #35454E;
overflow: hidden;
}
html *{
font-family: "Work Sans", Arial, sans-serif !important;
color: white !important;
}
table{
border-collapse: collapse;
border-spacing: 0px;
color:#35454E;
height:100%;
width:100%;
}
table, th{
border: 2px solid white;
padding:0;
}
th{
vertical-align:top;
font-size: 2.5vw;
}
td{
vertical-align:top;
box-sizing:border-box;
position: relative;
border: 2px solid white;
padding:0;
text-align: center;
font-size: 2.5vw;
padding:0;
}
.cellInputs{
position: absolute;
width:100%;
height:100%;
display: block;
top:0;
left:0;
border:none;
text-align: center;
background-color: #35454E;
word-wrap: break-word;
font-size: 2.5vw;
}
<html>
<head>
<link rel="stylesheet" type="text/css" href="MMS.css">
<title>Money Management</title>
</head>
<body>
<table id="mainTable">
<thead>
<tr>
<th>2019</th>
<th colspan="5">January</th>
</tr>
<tr id="weeks">
<th>&nbsp</th>
<th>31/12/2018</th>
<th>07/01/2019</th>
<th>14/01/2019</th>
<th>21/01/2019</th>
<th>28/01/2019</th>
</tr>
</thead>
<tbody>
<tr>
<th>Balance</th>
</tr>
<tr>
<th>Pay</th>
</tr>
<tr>
<th>&nbsp</th>
</tr>
<tr>
<th>Rent</th>
</tr>
<tr>
<th>Food</th>
</tr>
<tr>
<th>&nbsp</th>
</tr>
<tr>
<th>Total</th>
</tr>
</tbody>
</table>
</body>
<script src="MMS.js"></script>
</html>
Remove height:100% from table .

Create marque like effect in a table column using CSS

I have table like this:
<table>
<tr>
<td>Column1 Static</td>
<td>Column2 Static</td>
<td>Column3 with some long moving text</td>
</tr>
</table>
How can I create a marquee-like effect for the third column using CSS?
With some additional styling placed on the table, #Tats_innit's post on a javascript <marquee/>'s provides a great solution (JQuery).
(function($) {
$.fn.textWidth = function() {
var calc = '<span style="display:none">' + $(this).text() + '</span>';
$('body').append(calc);
var width = $('body').find('span:last').width();
$('body').find('span:last').remove();
return width;
};
$.fn.marquee = function(args) {
var that = $(this);
var textWidth = that.textWidth(),
offset = that.width(),
width = offset,
css = {
'text-indent': that.css('text-indent'),
'overflow': that.css('overflow'),
'white-space': that.css('white-space')
},
marqueeCss = {
'text-indent': width,
'overflow': 'hidden',
'white-space': 'nowrap'
},
args = $.extend(true, {
count: -1,
speed: 1e1,
leftToRight: false
}, args),
i = 0,
stop = textWidth * -1,
dfd = $.Deferred();
function go() {
if (!that.length) return dfd.reject();
if (width == stop) {
i++;
if (i == args.count) {
that.css(css);
return dfd.resolve();
}
if (args.leftToRight) {
width = textWidth * -1;
} else {
width = offset;
}
}
that.css('text-indent', width + 'px');
if (args.leftToRight) {
width++;
} else {
width--;
}
setTimeout(go, args.speed);
};
if (args.leftToRight) {
width = textWidth * -1;
width++;
stop = offset;
} else {
width--;
}
that.css(marqueeCss);
go();
return dfd.promise();
};
})(jQuery);
$('.marquee').marquee();
td {
min-width: 150px;
max-width: 150px;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<table>
<tr>
<td>Column1 Static</td>
<td>Column2 Static</td>
<td>
<div class="marquee">Column3 with some long moving text</div>
</td>
</tr>
</table>
Hope this helps,
Here's a pure CSS solution. The CSS property transform: translateX(), #keyframes, and CSS animation is used in the demo. If for some inconceivable reason your browser is pre-2017, a JavaScript prefix function is provided.
var animation = false,
animationstring = 'animation',
keyframeprefix = '',
domPrefixes = 'Webkit Moz O ms Khtml'.split(' '),
pfx = '',
elem = document.createElement('div');
if( elem.style.animationName !== undefined ) { animation = true; }
if( animation === false ) {
for( var i = 0; i < domPrefixes.length; i++ ) {
if( elem.style[ domPrefixes[i] + 'AnimationName' ] !== undefined ) {
pfx = domPrefixes[ i ];
animationstring = pfx + 'Animation';
keyframeprefix = '-' + pfx.toLowerCase() + '-';
animation = true;
break;
}
}
}
:root {
font: 400 16px/1.5 Verdana;
}
html,
body {
width: 100%;
height: 100%;
}
body {
overflow: hidden;
}
.table {
table-layout: fixed;
border-collapse: collapse;
width: 90%;
margin: 5px auto;
}
td {
width: 15%;
text-align: center;
border: 3px solid rgba(233, 233, 233, 0.3);
}
td:last-of-type {
width: 70%;
}
td>b {
display: block;
margin: -15px auto 0;
font-size: 1.5rem;
color: tomato;
}
.marquee {
width: 90%;
/* Required on Parent */
overflow: hidden;
background: rgba(0, 0, 0, 0.7);
padding-left: 15px;
margin: 20px auto;
font-size: 2rem;
}
.scroll {
/* Required on Child*/
white-space: nowrap;
display: table-cell;
color: cyan;
vertical-align: baseline;
/* Infinite Loops */
animation: rightToLeft 12s linear infinite;
/* Right to left direction */
animation-fill-mode: backwards;
/* Set to 0s in order to have a point of reference */
animation-delay: 0s;
}
.scroll::before {
content: 'πŸ‘„ ';
}
.scroll::after {
content: ' πŸ‘„';
}
.scroll a {
color: gold
}
/* Required for complex CSS animation */
#keyframes rightToLeft {
0% {
transform: translateX(20%);
}
100% {
transform: translateX(-100%);
}
}
<table class='table'>
<tbody>
<tr>
<td>15%<b>⟺</b></td>
<td>15%<b>⟺</b></td>
<td>
<figure class='marquee'>
<figcaption class='scroll'>You should read <i>β€œhow to ask”</i>: https://stackoverflow.com/help/how-to-ask</figcaption>
</figure>
</td>
</tr>
<tr>
<td>15%<b>⟺</b></td>
<td>15%<b>⟺</b></td>
<td>
<figure class='marquee'>
<figcaption class='scroll'>🎠🎠🎠🎠🎠🎠🎠🎠🎠🎠🎠🎠🎠🎠🎠🎠🎠🎠🎠🎠🎠🎠🎠🎠</figcaption>
</figure>
</td>
</tr>
</tbody>
</table>

Can't page break to work without messing up the table formatting

I have been having issues with page breaks in tables. Thought I had a solution as it was working fine in this SO question:
Inserting a page break into of <table> in React app
This worked fine for a table with one column, but nowt that I am working with multiple columns, it is a mess.
Basically I have to include display: block to get the page break to work properly, but that makes it go from a well formatted table to this:
I have gone down the list in MDN just trying anything that might work.
https://developer.mozilla.org/en-US/docs/Web/CSS/display
Furthermore, page breaks are only working when on their own separate <tr> which is undesirable since it generates a blank page. Got this sorted out by moving the pagebreak to the <tr> instead of the <td>.
I haven't been able to resolve these issues; any suggestions on how to approach this problem?
Not sure how useful a JSFiddle will be given the printing issue, but here is the compiled HTML. I can never get JSFiddle working with React:
https://jsfiddle.net/5gz62d91/
Best would probably be the Github repo:
https://github.com/ishraqiyun77/page-breaks
Here is the code separately:
import React, { Component } from 'react';
import ReactDOM from 'react-dom';
import styles from '../assets/scss/app.scss';
class PageBreakIssues extends Component {
// Render the data points
renderDataPoint() {
let dataPoint = [];
for (let i = 1; i <= 3; i++) {
let num = (Math.random() * 100).toFixed(2);
dataPoint.push(
<td className='data-point' key={ i }>
{ num < 25 ? null : num }
</td>
)
}
return dataPoint;
}
// Start generating the row data
renderDataRow() {
let dataRow = [];
for (let i = 1; i <= 5; i++) {
dataRow.push(
<tr key={ i }>
<td className='data-name' colSpan='3' key={i}>Test - { i }</td>
{ this.renderDataPoint() }
</tr>
)
}
return dataRow;
}
// Start generating table sections with the section name
// COMMENT THIS OUT TO TRY WITOUT ADDING A BLANK ROW
renderSections() {
let sections = [];
for (let i = 1; i <= 10; i++) {
sections.push(
<tbody key={ i }>
<tr key={ i }>
<td colSpan='7' className='section-name' key={i} >
Section - { i }
</td>
</tr>
{ this.renderDataRow() }
{
i % 2 === 0
?
<tr className='pagebreak'>
<td colSpan='7'></td>
</tr>
:
null
}
</tbody>
)
}
return sections;
}
// Start generating table sections with the section name
// UNCOMMENT THIS SECTION TO TRY WITHOUT INSERT BLANK TR
// renderSections() {
// let sections = [];
// for (let i = 1; i <= 10; i++) {
// sections.push(
// <tbody key={i}>
// <tr key={i}>
// <td colSpan='7' className={ i % 2 === 0? 'section-name pagebreak' : 'section-name'} key={i} >
// Section - {i}
// </td>
// </tr>
// {this.renderDataRow()}
// </tbody>
// )
// }
// return sections;
// }
// Render the table with <th>
render() {
return (
<table>
<thead>
<tr>
<th colSpan='3'>Results</th>
<th>1</th>
<th>2</th>
<th>3</th>
</tr>
</thead>
{ this.renderSections() }
</table>
)
}
}
ReactDOM.render(<PageBreakIssues />, document.getElementById('app'));
#mixin borders {
border: 1px solid black;
}
%borders {
#include borders;
}
table {
border-spacing: 0;
th {
text-align: center;
}
tr {
th{
#extend %borders;
}
td {
#extend %borders;
&.data-name {
padding: 3px 100px 3px 3px;
}
&.data-point {
text-align: center;
padding: 3px 10px;
}
&.section-name {
background-color: #999;
}
}
}
}
#media print {
tr {
display: block;
}
.pagebreak {
break-before: always !important;
page-break-before: always !important;
page-break-inside: avoid !important;
}
}
I figure out an even more hard-coding method (so call perfectly solve your problem). I must said it is not elegant.
My method's main idea is changing tbody to display:block (as usual), but adding the .pagebreak to target tbody as well.
However, this method unattach tbody from the table and thus no longer align with thead. That's why I add a tr for printing thead, and remove the origin thead when print.
Added printing th, don't show in normal view
//Thead part, add a printing thead only shown in Print
//As originaly thead will has alloction problem
{ i % 2 === 1 ?
<tr className='printing-thead'>
<td colspan="3">Results</td>
<td>1</td>
<td>2</td>
<td>3</td>
</tr> : null
}
....
...
//Corrected Page break
</tbody>
<tbody class="pagebreak">
<tr>
<td colspan="7"></td>
</tr>
</tbody>
<tbody>
...
Corresponding CSS
table {
border-spacing: 0;
table-layout: fixed;
th {
text-align: center;
}
tr {
th {
#extend %borders;
}
td {
#extend %borders;
&.data-name {
padding: 3px 100px 3px 3px;
}
&.data-point {
text-align: center;
padding: 3px 10px;
}
&.section-name {
background-color: #999;
}
}
}
tr.printing-thead {
display: none;
}
}
#media print {
thead {
display: none;
}
tbody {
display: block;
tr.printing-thead {
display: contents;
font-weight: bold;
text-align: center;
}
}
.pagebreak {
height: 0px;
break-before: always !important;
page-break-before: always !important;
page-break-inside: avoid !important;
td {
display: none;
}
}
}
The JSfiddle.
And the react version
JSfiddle React Version

How to fix the positioning of scroll bar using css

I have a table:- HTML Code
<div class="table-scroll">
<table class="my-table" cellpadding="0" cellspacing="0">
<thead>
<tr>
<th>firstName</th>
<th>lastName</th>
<th>age</th>
<th>email</th>
<th>balance</th>
<th>Mode</th>
<th>Total</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="row in rowCollection" ng-class-even="'striped'">
<td>{{row.Row1}}-{{row.Row2}}</td>
<td>{{row.Row3 != null ? row.Row3 : " "}}</td>
<td><div class="width">{{row.Row4 != null ? row.Row4 : " "}}</div></td>
<td>{{row.Row5 != null ? (row.Row2 >= "50"? row.Row5 : (row.Row5 | date:'dd-MMM-yyyy')) : " "}}</td>
<td>{{row.Row2}}</td>
<td>{{row.Row5}}</td>
</tr>
</tbody>
</table>
</div>
CSS Code:-
.table-scroll {
overflow-x: scroll;
overflow-y:hidden;
height:60vh;}
.width{
width:50%;
}
.my-table {
width: 100%; }
.my-table tbody tr {
outline: none; }
.my-table tbody, thead {
display: block; }
.my-table tbody{
overflow-y:scroll;
max-height:50vh;
}
.my-table td {
min-width: 90px;
font-size: .7em;
padding: 6px;
text-align: center;
border-bottom: 1px solid #ddd; }
.my-table th {
min-width: 90px;
background-color: #58595b;
font-size: .7em;
color: #ddd;
padding: 6px;
border-bottom: 1px solid #777;
font-weight: bold;
border-right: 1px solid #333;
border-left: 1px solid #777;
text-align: center; }
.striped {
background-color: #eeeff1; }
JS Code:-
angular.module('myApp', ['smart-table','lrDragNDrop'])
.controller('mainCtrl', ['$scope', '$timeout',
function ($scope, $timeout) {
var nameList = ['Pierre', 'Pol', 'Jacques', 'Robert', 'Elisa'];
var familyName = ['Dupont', 'Germain', 'Delcourt', 'bjip', 'Menez'];
$scope.isLoading = false;
$scope.rowCollection = [];
function createRandomItem() {
var
firstName = nameList[Math.floor(Math.random() * 4)],
lastName = familyName[Math.floor(Math.random() * 4)],
age = Math.floor(Math.random() * 100),
email = firstName + lastName + '#whatever.com',
balance = Math.random() * 3000;
return {
Row1: firstName,
Row2: lastName,
Row3: age,
Row4: email,
Row5: balance
};
}
$scope.columns=['Row1','Row2','Row3','Row4','Row5'];
for(var i=0;i<50;i++){
$scope.rowCollection.push(createRandomItem());
}
}
]);
https://plnkr.co/edit/YCXMSjAQ4VVSyvVFNLoI?p=preview
Here I am trying to fix the column headers and applying the vertical scroll to my tbody.
But the scroll appears at the very end when user scrolls through the horizontal scroll. I am trying to fix the position of vertical scroll but it changes my table look. Also, to achieve above I used display:block to tbody and thead but that ruins the alignment of columns. Can anybody please help me fixing the above issue.
.my-table tbody, thead {display: inline-block; }
.my-table th {min-width:92px;}