Print Preview changes html layout - html

I need to create a print preview of a receipt with a custom layout and ultimately print it. But my issue is; when I view it in my print preview, it is rendered differently from the layout I have created prior to clicking the 'Print Preview' button. In the sections where I used a table element, in my layout, I get the layout that I want, but in the print preview, the table shrinks. Please see my html codes below:
<div id="print-section" *ngIf="propertyLedger">
<h2>SPMIS</h2>
<hr>
<table class="table borderless">
<tr>
<th class="col-md-2">Transaction Date</th>
<td>{{dateToday | date}}</td>
</tr>
<tr>
<th class="col-md-2" style="text-align: left;">Collecting Agent</th>
<td>{{propertyLedger.CollectinAgentName}}</td>
</tr>
<tr>
<th class="col-md-2" style="text-align: left;">Unit Name</th>
<td>{{propertyLedger.UnitName}}</td>
</tr>
<tr>
<th class="col-md-2" style="text-align: left;">Payment Type</th>
<td>{{propertyLedger.PaymentType}}</td>
</tr>
<tr>
<th class="col-md-2" style="text-align: left;">O.R. Number</th>
<td>{{propertyLedger.ORNumber}}</td>
</tr>
<tr>
<th class="col=md-2" style="text-align: left;">Amount</th>
<td>{{ sumPayment() | currency: 'PHP ' }}</td>
</tr>
<tr>
<th class="col-md-2" style="text-align: left;">Remarks</th>
<td>{{propertyLedger.Remarks}}</td>
</tr>
</table>
<hr>
<h3>Details</h3>
<table class="table borderless" *ngIf="PropertyLedgerDetails">
<thead>
<tr>
<th class="col-md-2" style="text-align: left;">Transaction Type</th>
<th class="col-md-2" style="text-align: left;">Amount</th>
<th class="col-md-2" style="text-align: left;">Month</th>
<th class="col-md-2" style="text-align: left;">Year</th>
</tr>
</thead>
<tbody>
<tr *ngFor="let pd of PropertyLedgerDetails">
<td>{{pd.TransactionType}}</td>
<td>{{pd.Amount | currency: 'PHP '}}</td>
<td>{{pd.Month}}</td>
<td>{{pd.Year}}</td>
</tr>
</tbody>
</table>
<hr>
</div>
<br>
<button mat-raised-button color="default" class="btn pull-right" (click)="print()">Print</button>
before print preview
As soon as I click the Print Preview button (Print) this is what I get:
Can you please show me how to this right? Thank you so much for your help.
EDIT
I created a css like this
#media screen, print {
table {
table-layout: fixed;
width: 100%;
border-collapse: collapse;
border: 3px solid purple;
}
thead th:nth-child(1) {
width: 50%;
}
thead th:nth-child(2) {
width: 20%;
}
thead th:nth-child(3) {
width: 15%;
}
thead th:nth-child(4) {
width: 15%;
}
th, td {
padding: 20px;
}
}
I have to add this style in the part where I need to print the html.

Can you provide more details as to what is not the same? As per the running example bellow when you click on the print and the print preview shows ... they look pretty close to me.
#media screen,
print {
table {
table-layout: fixed;
width: 100%;
border-collapse: collapse;
border: 3px solid purple;
}
thead th:nth-child(1) {
width: 50%;
}
thead th:nth-child(2) {
width: 20%;
}
thead th:nth-child(3) {
width: 15%;
}
thead th:nth-child(4) {
width: 15%;
}
th,
td {
padding: 20px;
}
}
<div id="print-section" *ngIf="propertyLedger">
<h2>SPMIS</h2>
<hr>
<table class="table borderless">
<tr>
<th class="col-md-2" style="text-align: left;">Transaction Date</th>
<td>{{dateToday | date}}</td>
</tr>
<tr>
<th class="col-md-2" style="text-align: left;">Collecting Agent</th>
<td>{{propertyLedger.CollectinAgentName}}</td>
</tr>
<tr>
<th class="col-md-2" style="text-align: left;">Unit Name</th>
<td>{{propertyLedger.UnitName}}</td>
</tr>
<tr>
<th class="col-md-2" style="text-align: left;">Payment Type</th>
<td>{{propertyLedger.PaymentType}}</td>
</tr>
<tr>
<th class="col-md-2" style="text-align: left;">O.R. Number</th>
<td>{{propertyLedger.ORNumber}}</td>
</tr>
<tr>
<th class="col=md-2" style="text-align: left;">Amount</th>
<td>{{ sumPayment() | currency: 'PHP ' }}</td>
</tr>
<tr>
<th class="col-md-2" style="text-align: left;">Remarks</th>
<td>{{propertyLedger.Remarks}}</td>
</tr>
</table>
<hr>
<h3>Details</h3>
<table class="table borderless" *ngIf="PropertyLedgerDetails">
<thead>
<tr>
<th class="col-md-2" style="text-align: left;">Transaction Type</th>
<th class="col-md-2" style="text-align: left;">Amount</th>
<th class="col-md-2" style="text-align: left;">Month</th>
<th class="col-md-2" style="text-align: left;">Year</th>
</tr>
</thead>
<tbody>
<tr *ngFor="let pd of PropertyLedgerDetails">
<td>{{pd.TransactionType}}</td>
<td>{{pd.Amount | currency: 'PHP '}}</td>
<td>{{pd.Month}}</td>
<td>{{pd.Year}}</td>
</tr>
</tbody>
</table>
<hr>
</div>
<br>
<button mat-raised-button color="default" class="btn pull-right" onclick="window.print()">Print</button>

Related

How do I make div border to be flex but have minimum height?

StackOverflow.
I would like for the divs border where the information pane and tables are to have minimum height and also flex height when table content get out of the border.
Example:
link 1
link 2
Note: StackOverflow does not allow me to post picures yet as I am a new to the developers world. Please use the links provides. Thank you.
Html code:
<div class="searchAndTablesContainer">
<!-- Left panel-->
<div class="searchPanel">
Informational pane
<input class="button1 button2" type="submit" value="Get All Users" onclick="getAllUsers()">
<input class="button1 button2" type="submit" value="Get All Shop Services" onclick="getAllShopServices()">
</div>
<!-- Right Panel-->
<div class="tablesPanel">
<div id="passReset" style="display:block">
<table class="table table-striped">
<tr class="bg-info" style="text-align: center">
<th data-column="id" data-order="desc">Request ID &#9660</th>
<th data-column="account_email" data-order="desc">Account Email &#9660</th>
<th data-column="date_requested" data-order="desc">Date Requested &#9660</th>
<th data-column="date_restarted" data-order="desc">Date Restarted &#9660</th>
</tr>
<tbody id="passResetTable">
</tbody>
</table>
</div>
<div id="users" style="display:block">
<table class="table table-striped">
<tr class="bg-info" style="text-align: center">
<th data-column="id" data-order="desc">User ID &#9660</th>
<th data-column="first_name" data-order="desc">First Name &#9660</th>
<th data-column="last_name" data-order="desc">Last Name &#9660</th>
<th data-column="phone" data-order="desc">Phone&#9660</th>
<th data-column="email" data-order="desc">Email &#9660</th>
<th data-column="enabled" data-order="desc">Enabled &#9660</th>
</tr>
<tbody id="usersTable">
</tbody>
</table>
</div>
<div id="services" style="display:block">
<table class="table table-striped">
<tr class="bg-info" style="text-align: center">
<th data-column="id" data-order="desc">Shop Service ID &#9660</th>
<th data-column="first_name" data-order="desc">Service Name &#9660</th>
<th data-column="last_name" data-order="desc">Service Price &#9660</th>
</tr>
<tbody id="shopServicesTable">
</tbody>
</table>
</div>
</div>
</div>
</body>
CSS:
.searchAndTablesContainer {
width: 100%;
height: 500px;
margin: 5px;
}
.searchPanel {
width: 30%;
height: 100%;
float: left;
flex: auto;
background-color: white;
border-collapse: collapse;
outline:1px solid black;
}
.tablesPanel {
width: 68%;
height: 100%;
flex: auto;
float: left;
background-color: white;
border-collapse: collapse;
outline:1px solid black;
}
I would be very grateful to anyone who helps me out with this. Thank you in advance!
You can achieve this with display: flex for the container (and of course min-height). So you can also get rid of "float":
.searchAndTablesContainer {
display: flex;
flex-direction: row;
width: 100%;
min-height: 100px;
margin: 5px;
}
.searchPanel {
width: 30%;
background-color: white;
border-collapse: collapse;
outline: 1px solid black;
}
.tablesPanel {
width: 68%;
background-color: white;
border-collapse: collapse;
outline: 1px solid black;
}
<div class="searchAndTablesContainer">
<!-- Left panel-->
<div class="searchPanel">
Informational pane
<input class="button1 button2" type="submit" value="Get All Users" onclick="getAllUsers()">
<input class="button1 button2" type="submit" value="Get All Shop Services" onclick="getAllShopServices()">
</div>
<!-- Right Panel-->
<div class="tablesPanel">
<div id="passReset" style="display:block">
<table class="table table-striped">
<tr class="bg-info" style="text-align: center">
<th data-column="id" data-order="desc">Request ID &#9660</th>
<th data-column="account_email" data-order="desc">Account Email &#9660</th>
<th data-column="date_requested" data-order="desc">Date Requested &#9660</th>
<th data-column="date_restarted" data-order="desc">Date Restarted &#9660</th>
</tr>
<tbody id="passResetTable">
</tbody>
</table>
<p>test</p>
<p>test</p>
<p>test</p>
<p>test</p>
<p>test</p>
</div>
<div id="users" style="display:block">
<table class="table table-striped">
<tr class="bg-info" style="text-align: center">
<th data-column="id" data-order="desc">User ID &#9660</th>
<th data-column="first_name" data-order="desc">First Name &#9660</th>
<th data-column="last_name" data-order="desc">Last Name &#9660</th>
<th data-column="phone" data-order="desc">Phone&#9660</th>
<th data-column="email" data-order="desc">Email &#9660</th>
<th data-column="enabled" data-order="desc">Enabled &#9660</th>
</tr>
<tbody id="usersTable">
</tbody>
</table>
</div>
<div id="services" style="display:block">
<table class="table table-striped">
<tr class="bg-info" style="text-align: center">
<th data-column="id" data-order="desc">Shop Service ID &#9660</th>
<th data-column="first_name" data-order="desc">Service Name &#9660</th>
<th data-column="last_name" data-order="desc">Service Price &#9660</th>
</tr>
<tbody id="shopServicesTable">
</tbody>
</table>
</div>
</div>
</div>

How to use width in a table border?

I am trying to implement cellpadding and cellspacing in my forum, but I just can't get the width="100%" to work with it.
Is it possible to set a width while using cellpadding or cellspacing in my CSS?
.categories div.category td tr{
padding: 80px;
width: 500px;
}
echo '
<table class="categories">
<caption>Category: ', $row2['category'], '</caption>
<thead>
<tr>
<td colspan="3">
<th colspan="3"><a href="create_music_sub.php?cat='.$row2['id'].'&admin='.$row2['admin'].'">
Click here to Create Sub Category
</a></th>
</td>
</tr><tr>
<div class="category"><th scope="col">Category</th></div>
<th scope="col">Creator</th>
<th scope="col">Date Created</th>
</tr>
</thead><tbody>';
If what you meant is to set the table's width to 100%, this works.
And as for the code you provided there were mistakes:
When you want to use a th you don't use a td with it.
The div.category should be inside the tr > th not wrapping it.
When you're posting a question please remove the php fragments and provide a working fiddle for us to be able to help you faster.
Please look at the code to see what I did differently. I think the problem was in your html
table{
border:1px solid black;
width: 100%;
}
tr, th, td{
border:1px solid black;
}
td,th{
padding: 10px;
}
/*If you want the last column to be smaller you can change one of them to a certain width*/
.creator{
width:20%;
}
<table class="categories">
<caption>Category: 1</caption>
<thead>
<tr>
<th colspan="3">
Click here to Create Sub Category
</th>
</tr>
<tr>
<th scope="col">
<div class="category">Category</div>
</th>
<th scope="col">Creator</th>
<th scope="col">Date Created</th>
</tr>
<tr>
<th colspan="2" scope="col">
<div class="category">Category</div>
</th>
<th scope="col">Creator</th>
</tr>
</thead>
</table>
<table class="categories">
<caption>Category: 1</caption>
<thead>
<tr>
<th colspan="3">
Click here to Create Sub Category
</th>
</tr>
<tr>
<th scope="col">
<div class="category">Category</div>
</th>
<th scope="col">Creator</th>
<th scope="col">Date Created</th>
</tr>
<tr>
<th colspan="2" scope="col">
<div class="category">Category</div>
</th>
<th scope="col" class="creator">Creator</th>
</tr>
</thead>
</table>

How to add multiple header HTML table?

I want to Design a table that has multiple headers. The table design is there:
Have a look at this fiddle
All about colspan and rowspan
<table>
<thead>
<tr>
<th rowspan="2" colspan="1" >
Client Name
</th>
<th rowspan="2" colspan="1">
Date
</th>
<th rowspan="1" colspan="5">
All Appointments
</th>
<th rowspan="1" colspan="3" >
Fulfilled Appointments
</th>
</tr>
<tr>
<th>Total number of individual appointments</th>
<th >Hours Of Care Delivered</th>
<th>Total Value</th>
<th>Average Cost Per Hour</th>
<th>Average Cost Per Hour Per Carer</th>
<th>Total Number</th>
<th>Hours Of Care Fulfilled</th>
<th>Total Value</th>
</tr>
</thead>
<tbody></tbody>
</table>
<html>
<head>
<title>Table</title>
<style>
table,th,td {
border: 2px solid red;
border-collapse: collapse;
}
.heightu{
height: 212px;
}
div.First {
border: 1px solid red;
width: 49px;
height:10px;
left: 15px;
}
div.Second {
border: 1px solid red;
width: 49px;
height:10px;
left: 15px;
}
div.Third {
border: 1px solid red;
width: 39px;
height:10px;
left: 15px;
}
</style>
</head>
<body>
<table>
<tr>
<th rowspan="2">Sl.No</th>
<th rowspan="2">Name</th>
<th colspan="2">Date:15/05/2021</th>
<th rowspan="2">Do </th>
</th>
</tr >
<tr>
<th rowspan=>Start Hour</th>
<th rowspan=>End Hour</th>
</tr>
<tr>
<td>1</td>
<td>John Ddoe</td>
<td ><div class="First"></div></td>
<td><div class="Second"> </div></td>
<td><div class="Third"></div></td>
</tr>
<tr class="heightu">
<td></td>
<td></td>
</td>
<td ></td>
<td ></td>
<td ></td>
</tr>
</table>
</body>
</html>

Bootstrap Table - Move cell to the right to properly display the total

Good evening, I'm trying to align a table to make it like the picture, but failed to do so, I could help?
Now I have it like this:
and I'd like it to look like this:
This is my html code:
<table class="table table-hover table-bordered">
<thead>
<tr>
<th class="text-left">Codigo</th>
<th class="text-left">Descripcion</th>
<th class="text-left">Precio</th>
<th class="text-left">Cantidad</th>
<th class="text-left">Importe</th>
</tr>
</thead>
<tbody>
<tr>
<td class="col-md-1">1001</td>
<td class="col-md-8">Producto de ejemplo 1</td>
<td class="col-md-1 text-right">$10,000</td>
<td class="col-md-1 text-center">100</td>
<td class="col-md-1 text-right">$1,000,000</td>
</tr>
<tr>
<th class="text-right" scope="row">TOTAL</th>
<td class="text-right">$1,000,000</td>
</tr>
</tbody>
</table>
Specifying the colspan for the cells in the summary row will shift the final cell right.
<th colspan="4" class="text-right" scope="row">TOTAL</th>
Alternatively, you could start the row with a <td> with colspan="3", and using a class that would have no borders (controlled by your css).
<td colspan="3" class="noborders"></td>
<th class="text-right" scope="row">TOTAL</th>
Without that class, direct manipulation of style may work.
<td style="border:0" colspan="3"></td>
<th class="text-right" scope="row">TOTAL</th>
Updated snippet:
table {
border-collapse: collapse;
font-family: arial;
}
td,
th {
width: auto;
margin: 2px;
padding: 3px;
text-align: left;
border: 1px solid grey;
}
.noborders {
border: 0;
}
.text-left {
text-align: left;
}
.text-center {
text-align: center;
}
.text-right {
text-align: right;
}
<table class="table table-hover table-bordered">
<thead>
<tr>
<th class="text-left">Codigo</th>
<th class="text-left">Descripcion</th>
<th class="text-left">Precio</th>
<th class="text-left">Cantidad</th>
<th class="text-left">Importe</th>
</tr>
</thead>
<tbody>
<tr>
<td class="col-md-1">1001</td>
<td class="col-md-8">Producto de ejemplo 1</td>
<td class="col-md-1 text-right">$10,000</td>
<td class="col-md-1 text-center">100</td>
<td class="col-md-1 text-right">$1,000,000</td>
</tr>
<tr>
<td colspan="3" class="noborders"></td>
<th class="text-right" scope="row">TOTAL</th>
<td class="text-right">$1,000,000</td>
</tr>
</tbody>
</table>

div overlapping a table

I have tried various options such as overlap and suchlike, but I can't stop a div from overlapping a table to the right.
I have created a fiddle for my code http://jsfiddle.net/ntEzL/ to help explain my issue.
<div style="border: 1px solid #c9c3ba; padding: 0.5em; background-color: #f1f0ee; overflow: hidden;">
<br>
<br>
<table class="ff_sidebox" cellspacing="5" style="width:22em;">Latvia
<tr class="">
<th scope="row" style="text-align:left; white-space: nowrap">Full Name</th>
<td class="" style="white-space: nowrap">Republic of Latvia</td>
</tr>
<tr class="">
<th scope="row" style="text-align:left; white-space: nowrap">Full Name</th>
<td class="" style="white-space: nowrap">Republic of Latvia</td>
</tr>
<tr class="">
<th scope="row" style="text-align:left; white-space: nowrap">Full Name</th>
<td class="" style="white-space: nowrap">Republic of Latvia</td>
</tr>
<tr class="">
<th scope="row" style="text-align:left; white-space: nowrap">Full Name</th>
<td class="" style="white-space: nowrap">Republic of Latvia</td>
</tr>
<tr class="">
<th scope="row" style="text-align:left; white-space: nowrap">Full Name</th>
<td class="" style="white-space: nowrap">Republic of Latvia</td>
</tr>
<tr class="">
<th scope="row" style="text-align:left; white-space: nowrap">Full Name</th>
<td class="" style="white-space: nowrap">Republic of Latvia</td>
</tr>
<tr class="">
<th scope="row" style="text-align:left; white-space: nowrap">Full Name</th>
<td class="" style="white-space: nowrap">Republic of Latvia</td>
</tr>
<tr class="">
<th scope="row" style="text-align:left; white-space: nowrap">Full Name</th>
<td class="" style="white-space: nowrap">Republic of Latvia</td>
</tr>
<tr class="">
<th scope="row" style="text-align:left; white-space: nowrap">Full Name</th>
<td class="" style="white-space: nowrap">Republic of Latvia</td>
</tr>
<tr class="">
<th scope="row" style="text-align:left; white-space: nowrap">Full Name</th>
<td class="" style="white-space: nowrap">Republic of Latvia</td>
</tr>
</table>
<!-- end of sidebox for Latvia -->
<br>
<br>
<div class="ff_other_articles_caption" id="recent_articles_caption">Recent articles on Latvia</div>
<div class="ff_other_articles" id="recent_articles">
<div class="ff_other_articles_inner" id="recent_articles_inner">
<ul class="block_list">
<li> Latvia becomes 18th Euro Member on Jan 1st
</li>
</ul>
</div>
</div>
<br>
<br>
<br>
</div>
On a wider screen then there is no issue, but on a smaller resolution then I get the problem.
I would rather the content of the left box (div) to scroll to two lines if it can't fit there.
Any thoughts?
Thanks.
Try this..
for .ff_other_articles styles, remove position: absolute and add width:33%
Remove
position : absolute;
and add
width: 40% !important;
in class 'ff_other_articles' and check the changes i have made in html.
fiddle : http://jsfiddle.net/LPJAa/
Thanks.
why not use css table for this....??
i haved removed <br /> for easier understanding....and removed floats too, as they are not needed if you use floats..here is the demo
html, body {
width:100%;
height:100%;
margin:0;
padding:0;
}
#main_container {
display:table;
width:100%;
border:1px dashed #000;
}
.table_box_1 {
display:table-cell;
width:200px;
border:1px dashed red;
}
.table_box_2 {
display:table-cell;
width:50%;
border:1px dashed red;
}
Both float:left; and position:absolute; cannot be together.In this case remove absolute positioning from the left side box:
If i guess right this is what you asked for:
Fiddle 1 or Fiddle 2
Click to see updated fiddle:- With code / fullscreen