Fixed the table header with a scrolling panel - php

I know this is a duplicate question and I've tried every possible solution but not succeeded. I am using a panel in which my excel data is showing and I wanna fix the column in other words header. Every css I've tried break the panel settings and I didn't succeed. I'm using bootstrap css & have more than 1000 rows that's why I need a fixed header.
This is my HTML
<div class="panel panel-primary">
<div class="panel-heading">Excel Sheet</div>
<div class="panel-body">
<?php
echo '<table class="table table-striped table-hover table-condensed">';
echo "<thead class='thead'>";
echo "<tr class='info'>";
for ($column = 'A'; $column < $lastcol; $column++) {
echo "<th>";
echo $worksheet->getCell($column . '1')->getFormattedValue();
echo "</th>";
}
echo "</tr>";
echo '</thead>';
echo '<tbody>';
for ($row = 2; $row <= $lastrow; $row++) {
echo "<tr>";
for ($column = 'A'; $column < $lastcol; $column++) {
echo "<td>";
echo $worksheet->getCell($column . $row)->getFormattedValue();
echo "</td>";
}
echo "</tr>";
}
echo '</tbody>';
echo "</table>";
?>
</div>
</div>
Here is column and row 1 are for loop, which will give the header. I have used integrated php-html. Other rows will appear in row for loop.
this is my css and commented code is last code i have tried.
.panel-heading{
font-size: 15px;
}
.panel-body{
overflow:auto;
height:400px;
}
tr{
border: 1px solid black;
}
th{
border: 1px solid black;
}
td{
border: 1px solid black;
}
example fiddle is Here
P.S : Please dont forget to place a comment in case of negative vote for helping me . Cheers !

Try adding the below CSS to your .panel-primary:
.panel-primary{
top: 0;
}
This should do it.
Hope it helps.

You can make this with Jquery. I check the width of each first td for define each th width.
$(document).ready(function(){
resized();
})
$(window).resize(function(){
resized()
})
function resized(){
var widthTd1 = $("td:eq(0)").width();
var widthTd2 = $("td:eq(1)").width();
var widthTd3 = $("td:eq(2)").width();
var TDPadding = 11; // = padding + border
var widthTH1 = widthTd1 + TDPadding;
var widthTH2 = widthTd2 + TDPadding;
var widthTH3 = widthTd3 + TDPadding;
$("th:eq(0)").css({width:widthTH1 })
$("th:eq(1)").css({width:widthTH2 })
$("th:eq(2)").css({width:widthTH3 })
}
$(".panel-body").on("scroll",function(){
$(".info").offset({top:58})
})
.panel-primary {
top: 0;
}
.panel-heading {
font-size: 15px;
}
.panel-body {
overflow: auto;
height: 400px;
padding:0 !important;
margin:15px
}
.info{
position:absolute;
left:-1px;
}
.table{
position:relative;
}
tbody::before {
content: "-";
display: block;
line-height: 2em;
}
th {
border: 1px solid black;
}
td {
border: 1px solid black;
}
<link href="https://netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="panel panel-primary">
<div class="panel-heading">Excel Sheet</div>
<div class="panel-body">
<table class="table table-striped table-hover table-condensed">
<thead class='thead'>
<tr class='info'>
<th>
Qc Code
</th>
<th>
Sample ID
</th>
<th>
Date
</th>
</tr>
</thead>
<tbody>
<tr>
<td>
SE68
</td>
<td>
GC57052
</td>
<td>
1/2/15 17:24
</td>
</tr>
<tr>
<td>
SE68
</td>
<td>
GC57052
</td>
<td>
1/2/15 17:24
</td>
</tr>
<tr>
<td>
SE68
</td>
<td>
GC57052
</td>
<td>
1/2/15 17:24
</td>
</tr>
<tr>
<td>
SE68
</td>
<td>
GC57052
</td>
<td>
1/2/15 17:24
</td>
</tr>
<tr>
<td>
SE68
</td>
<td>
GC57052
</td>
<td>
1/2/15 17:24
</td>
</tr>
<tr>
<td>
SE68
</td>
<td>
GC57052
</td>
<td>
1/2/15 17:24
</td>
</tr>
<tr>
<td>
SE68
</td>
<td>
GC57052
</td>
<td>
1/2/15 17:24
</td>
</tr>
<tr>
<td>
SE68
</td>
<td>
GC57052
</td>
<td>
1/2/15 17:24
</td>
</tr>
<tr>
<td>
SE68
</td>
<td>
GC57052
</td>
<td>
1/2/15 17:24
</td>
</tr>
<tr>
<td>
SE68
</td>
<td>
GC57052
</td>
<td>
1/2/15 17:24
</td>
</tr>
<tr>
<td>
SE68
</td>
<td>
GC57052
</td>
<td>
1/2/15 17:24
</td>
</tr>
<tr>
<td>
SE68
</td>
<td>
GC57052
</td>
<td>
1/2/15 17:24
</td>
</tr>
<tr>
<td>
SE68
</td>
<td>
GC57052
</td>
<td>
1/2/15 17:24
</td>
</tr>
<tr>
<td>
SE68
</td>
<td>
GC57052
</td>
<td>
1/2/15 17:24
</td>
</tr>
</tbody>
</table>
</div>
</div>

Related

Invoice pdf in php with wkhtmltopdf snappy Laravel

Hi every body i have to make an invoice pdf in my LARAVEL project.
I succeeed to generate a pdf with this code :
$path_name_file = '../ArchivePdf/'. $name_file . '.pdf';
if ($document->type->type == 'A'){
$pdf = SnappyPdf::loadView('ribbon.report.pdf-achat', ['document' =>$document])
->save($path_name_file);
}else{
$pdf = SnappyPdf::loadView('ribbon.report.pdf-new', ['document' =>$document])->save($path_name_file);
}
My problem is in the blade view (HTML template) that i want to put an header and a footer and a main table with items
I want that the footer will be on all pages
How can i do that?
Thanks
That is my actual html view:
<!DOCTYPE html>
<html>
<header>
<meta charset="utf-8">
<title>PDF Devis</title>
{{--<link href="{{ asset("/css/style_pdf.css")}}" rel="stylesheet" type="text/css" />--}}
<style>
.header-1{
border-top-left-radius: 7px;
border-top-right-radius: 7px;
/*left: 5%;*/
width: 100%;
border-style: solid;
font-size: 13px;
border-width: 2px;
}
th {
background-color: rgba(158, 158, 158, 0.22);
text-align: center;
}
.line{
width: 100%;
}
.line tr{
padding: 0;
}
.td-20{
width:20%
}
.td-30{
width:30%
}
.td-70{
width: 70%;
}
.td-40{
width: 40%;
}
.td-50{
width: 50%;
}
.img img{
width:100%; height:auto;
}
.name-soc{
font-size: 25px;
color: orangered;
direction: rtl;
font-family: arial;
font-style: bold;
}
.space{
padding-top: 20px;
}
.title{
font-weight: bold;
height: 50px;
color: white;
background-color: rgba(255, 87, 34, 0.89);
font-size: 25px;
border-radius: 5px;
bottom: 15px;
text-align: center;
}
.items{
}
.more_line{
height: 17px;
}
/*.items-table{*/
/*page-break-after: always;*/
/*page-break-inside: avoid;*/
/*}*/
thead { display: table-header-group }
tfoot { display: table-row-group }
.items-row { page-break-inside: avoid }
table { border-collapse: separate }
.note-table{
text-align: right;
width: 100%;
}
</style>
</header>
<body>
<table class="line">
<tr>
<td rowspan="4" class="td-30">
<div class="img"> <img src="{{ public_path('/ribbon/pdf/fre.jpg') }}" alt="logo"/></div>
</td>
<td class="td-30">
<div></div>
</td>
<td class="td-40">
<div class="name-soc">
דקופלוס פרקט בע״מ
</div>
</td>
</tr>
<tr>
<td class="td-30">
<div></div>
</td>
<td class="td-40">
<div class="name-soc">
</div>
</td>
</tr>
<tr>
<td class="td-20">
<div></div>
</td>
<td class="td-20">
<div></div>
</td>
</tr>
<tr>
<td class="td-20">
<div></div>
</td>
<td class="td-20">
<div></div>
</td>
</tr>
</table>
<table class="line">
<tr class="entete">
<td class="logo">
</td>
<td class="donnee_soc">
<div dir="rtl">{{trans('dcp_pdf.num_doc')}} : {{ $document->code }} </div>
</td>
</tr>
<tr>
<td class="td-50">
<div>
<table class="header-1" dir="rtl">
<tr>
<th colspan="2">{{trans('dcp_pdf.coord_cust')}}</th>
</tr>
<tr class="" >
<td>
<div style="width: 20%">{{trans('dcp_pdf.name')}}</div>
</td>
<td>
<div class="encadre_data">{{ $document['customer']['name'] }} {{ $document['customer']['surname'] }}</div>
</td>
</tr>
<tr class="" >
<td>
<div style="width: 20%">{{trans('dcp_pdf.adress')}}</div>
</td>
<td>
<div class="encadre_data">{{ $document['adress']['street'] }} {{ $document->adress->city->cityT[0]->texte }}</div>
</td>
</tr>
<tr class="" >
<td>
<div style="width: 20%">{{trans('dcp_pdf.telephone')}}</div>
</td>
<td>
<div class="encadre_data">{{ $document['customer']['phone'] }} / {{ $document['customer']['phone2'] }}</div>
</td>
</tr>
<tr class="" >
<td>
<div style="width: 20%">{{trans('dcp_pdf.mail')}}</div>
</td>
<td>
<div class="encadre_data">{{ $document['customer']['email'] }}</div>
</td>
</tr>
</table>
</div>
</td>
<td class="td-50">
<div>
<table class="header-1" dir="rtl">
<tr>
<th colspan="2">{{trans('dcp_pdf.coord_fact')}}</th>
</tr>
<tr class="" >
<td>
<div style="width: 20%">{{trans('dcp_pdf.name')}}</div>
</td>
<td>
<div class="encadre_data">{{ $document['customer']['name'] }} {{ $document['customer']['surname'] }}</div>
</td>
</tr>
<tr class="" >
<td>
<div style="width: 20%">{{trans('dcp_pdf.adress')}}</div>
</td>
<td>
<div class="encadre_data">{{ $document['adress']['street'] }} {{ $document->adress->city->cityT[0]->texte }}</div>
</td>
</tr>
<tr class="" >
<td>
<div style="width: 20%">{{trans('dcp_pdf.telephone')}}</div>
</td>
<td>
<div class="encadre_data">{{ $document['customer']['phone'] }} / {{ $document['customer']['phone2'] }}</div>
</td>
</tr>
<tr class="" >
<td>
<div style="width: 20%">{{trans('dcp_pdf.mail')}}</div>
</td>
<td>
<div class="encadre_data">{{ $document['customer']['email'] }}</div>
</td>
</tr>
</table>
</div>
</td>
</tr>
<tr >
<td colspan="2" class="space">
<div>
<table class="header-1" dir="rtl">
<tr>
<th colspan="2">{{trans('dcp_pdf.coord_livraison')}}</th>
</tr>
<tr class="" >
<td>
<div style="width: 20%">{{trans('dcp_pdf.name')}}</div>
</td>
<td>
<div class="encadre_data">{{ $document['customer']['name'] }} {{ $document['customer']['surname'] }}</div>
</td>
</tr>
<tr class="" >
<td>
<div style="width: 20%">{{trans('dcp_pdf.adress')}}</div>
</td>
<td>
<div class="encadre_data">{{ $document['adress']['street'] }} {{ $document->adress->city->cityT[0]->texte }}</div>
</td>
</tr>
<tr class="" >
<td>
<div style="width: 20%">{{trans('dcp_pdf.telephone')}}</div>
</td>
<td>
<div class="encadre_data">{{ $document['customer']['phone'] }} / {{ $document['customer']['phone2'] }}</div>
</td>
</tr>
<tr class="" >
<td>
<div style="width: 20%">{{trans('dcp_pdf.mail')}}</div>
</td>
<td>
<div class="encadre_data">{{ $document['customer']['email'] }}</div>
</td>
</tr>
</table>
</div>
</td>
</tr>
<tr >
<td colspan="2" class="space">
<div class="title" dir="rtl">
{{ $document->type->typeT[0]->texte }} - {{ $document->code }}
</div>
</td>
</tr>
<tr >
<td colspan="2" class="space">
<table class="items header-1 items-table" dir="rtl">
<thead>
<tr class="more_line">
<th class="Désignation" >{{trans('dcp_pdf.desc_article')}}</th>
<th class="other">{{trans('dcp_pdf.conditionnement')}}</th>
<th class="other">{{trans('dcp_pdf.quantity_m2')}}</th>
<th class="other">{{trans('dcp_pdf.nb_colis')}}</th>
<th class="other">{{trans('dcp_pdf.pu_ht')}}</th>
<th class="other">{{trans('dcp_pdf.discount')}}</th>
<th class="other">{{trans('dcp_pdf.total_ht')}}</th>
</tr>
</thead>
#foreach($document->items as $item)
<tr class="1 items-row">
<td class="Designation" dir="rtl"><div dir="rtl">{{ $item->material->textes[0]->texte }}</div></td>
<td class="Cdt"></td>
<td class="Qtem2">{{ $item->quantity }}</td>
<td class="Nb_colis">{{ $item->qte_col }}</td>
<td class="PU">{{ number_format($item->price, 2, '.', ',') }}</td>
<td class="Rem">{{ number_format($item->discount, 2, '.', ',') }} {{ $item->typeRemise->code }}</td>
<td class="Total"> {{ number_format($item->price_wo_vat, 2, '.', ',') }}</td>
</tr>
#endforeach
#for ($i = $document->items->count(); $i < 20; $i++)
<tr class="more_line">
<td class="Designation" dir="rtl"><div dir="rtl"></div></td>
<td class="Cdt"></td>
<td class="Qtem2"></td>
<td class="Nb_colis"></td>
<td class="PU"></td>
<td class="Rem"></td>
<td class="Total"></td>
</tr>
#endfor
</table>
</td>
</tr>
<tr >
<td colspan="2" >
<table class="note-table" dir="rtl">
<tr class="" >
<td>
<div class="encadre_data">{{ $document['note'] }} </div>
</td>
</tr>
<tr class="" >
<td >
<div class="encadre_data">{{ $document['comment'] }} </div>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td class="td-30">
<div>
<table class="header-1" dir="rtl">
<tr>
<td>{{trans('dcp_pdf.montant_ht')}}</td>
<td>{{ number_format($document->amount_wo_taxe, 2, '.', ',') }}</td>
</tr>
<tr>
<td>{{trans('dcp_pdf.dont_remise')}}</td>
<td></td>
</tr>
#if ($document['customer']['code_tva'] === 1)
<tr>
<td>{{trans('dcp_pdf.tva')}} {{ number_format($document->taxe, 2, '.', ',') }} %</td>
<td>{{ number_format($document->amount - $document->amount_wo_taxe, 2, '.', ',') }}</td>
</tr>
#endif
<tr>
<td>{{trans('dcp_pdf.montant_ttc')}}</td>
<td>{{ number_format($document->amount, 2, '.', ',') }}</td>
</tr>
<tr>
<td></td>
<td></td>
</tr>
<tr>
<td></td>
<td></td>
</tr>
</table>
</div>
</td>
<td class="td-70">
<div>
<table class="header-1" dir="rtl">
<tr>
<th colspan="4">{{trans('dcp_pdf.reglements')}}</th>
</tr>
<tr>
<th>{{trans('dcp_pdf.date')}}</th>
<th>{{trans('dcp_pdf.description')}}</th>
<th>{{trans('dcp_pdf.montant')}}</th>
<th>{{trans('dcp_pdf.mode_paiement')}}</th>
</tr>
#foreach($document->reglements as $reglement)
<tr>
<td>{{ $reglement->date }}</td>
<td>{{ $reglement->description }}</td>
<td>{{ number_format($reglement->amount, 2, '.', ',') }}</td>
<td>{{ $reglement->mode->modePaiementT[0]->texte }}</td>
</tr>
#endforeach
</table>
</div>
</td>
</tr>
<tr>
<td>
<div></div>
</td>
<td>
<div></div>
</td>
</tr>
<tr>
<td>
<div></div>
</td>
<td>
<div></div>
</td>
</tr>
<tr>
<td>
<div></div>
</td>
<td>
<div></div>
</td>
</tr>
<tr>
<td>
<div></div>
</td>
<td>
<div></div>
</td>
</tr>
<tr>
<td>
<div></div>
</td>
<td>
<div></div>
</td>
</tr>
</table>
</body>
</html>
Here is the documentation about header and footer with Wkhtmltopdf support.
You can try
For Header
setOption('header-html', 'Your Header');
For Footer
setOption('footer-html', 'Your Footer');
Just make sure that you need to add <!DOCTYPE HTML><html lang='en-US'> in the beginning of your header/footer HTML!

Print page setup in PHP

Am currently developing a web application which does the process of invoice etc.
Customer is using dot matrix printer to print invoice sheet. They said the requirement in printing as if there is more than 5 items in a sheet the rest should come as next sheet.
I have made that using PHP but i don't know how to print the next sheet in next page. It just prints as usual in sequence which results in a sheet printed in 2 pages. Any help or ideas will be appreciated. Below is the code how i generated sheet.
Thanks
<script type="text/javascript">
function printPage(){
var divElements = document.getElementById('printDataHolder').innerHTML;
var oldPage = document.body.innerHTML;
document.body.innerHTML="<link rel='stylesheet' href='css/common.css' type='text/css' /><body class='bodytext'>"+divElements+"</body>";
window.print();
document.body.innerHTML = oldPage;
}
</script>
<?php
$limit=5;
$cnt=0; // for table header and footer
$cnt2=1;// for no of rows count to print total values in end
$total=0;
?>
<div id="contentHolder" align="center">
<input type="button" value="Print" class="btnclass" onclick="printPage()" /> <input type="button" class="btnclass" value="Click to Proceed" style="width:100px;" onclick="Javascript:window.location.href='invoice.php';" />
<br />
<div id="printDataHolder">
<?php while($data=mysql_fetch_array($invcontents)){ ?>
<?php if($cnt==0){ ?>
<table width="800" border="0" cellspacing="0" cellpadding="0" style="border:1px solid #4E9A91;">
<tr>
<td height="29" colspan="4" style="font-size:22px; padding-left:10px;"><strong>OvalTechnologies</strong></td>
</tr>
<tr>
<td colspan="4" style="padding-left:10px;"><?php echo($branchdetails['address']); ?></td>
</tr>
<tr>
<td height="19" colspan="4" style="padding-left:10px;">Website : www.ovaltechnologies.in Phone No : <?php echo($branchdetails['phoneno']); ?></td>
</tr>
<tr>
<td height="12" colspan="4" style="border-bottom:1px solid #4E9A91;"> </td>
</tr>
<tr>
<td height="28" colspan="3" style="padding-left:10px;">Customer Name : <?php echo($invtotal['customername']); ?></td>
<td width="226"> </td>
</tr>
<tr>
<td width="309" height="28" style="padding-left:10px;border-bottom:1px solid #4E9A91;">Invoice No : <?php echo($invoiceid); ?></td>
<td colspan="2" style="border-bottom:1px solid #4E9A91;">Paid As : <?php echo($invtotal['paidas']); ?></td>
<td style="border-bottom:1px solid #4E9A91;">Date : <?php echo(getonlydatefromdatetime(changefromdbdate($invtotal['invoicedate']))); ?></td>
</tr>
<tr>
<td height="28" class="rowborder" style="padding-left:10px;"><strong>Item Name</strong></td>
<td width="136" class="rowborder"><strong>Rate</strong></td>
<td width="129" class="rowborder"><strong>Qty</strong></td>
<td class="rowborder"><strong>Amount</strong></td>
</tr>
<?php } ?>
<tr>
<td align="center" height="28" style="padding-left:10px;"><?php echo($data['item']); ?> : <?php echo($data['brand']." "); ?><?php echo($data['type']); ?></td>
<td align="center"><?php echo($data['billedamount']); ?></td>
<td align="center"><?php echo($data['quantity']); ?></td>
<td align="center"><?php echo($data['billedamount']*$data['quantity']); ?></td>
</tr>
<?php
if($cnt2==$invcount){//printing emptylines to fill up page
for($i=$cnt+1;$i<$limit;$i++){
?>
<tr>
<td height="28" style="padding-left:10px;"> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<?php
}
}//printing emptylines to fill page ends
?>
<?php if($cnt==$limit-1 || $cnt2==$invcount){ ?>
<?php if($invtotal['transport']!="") {?>
<tr>
<td style="padding-left:10px; border-top:1px solid #4E9A91;" class="rowborder" height="28">Transport : <?php echo($invtotal['transport']); ?></td>
<td class="rowborder" style="border-top:1px solid #4E9A91;">Transport Cost : <?php echo($invtotal['transportcost']); ?></td>
<td class="rowborder" style="border-top:1px solid #4E9A91;">Destination : <?php echo($invtotal['destination']); ?></td>
<td class="rowborder" style="border-top:1px solid #4E9A91;"> </td>
</tr>
<?php } ?>
<tr>
<td height="28" class="rowborder" style="border-top:1px solid #4E9A91;"> </td>
<td class="rowborder" style="border-top:1px solid #4E9A91;"><?php if($invtotal['transport']!="") {if($invtotal['addtransport']=="no"){echo("Transport Cost Not Added");}}?></td>
<td class="rowborder" style="border-top:1px solid #4E9A91;">Total</td>
<td class="rowborder" style="border-top:1px solid #4E9A91;"><?php echo($invtotal['totalamount']);?></td>
</tr>
<tr>
<td height="28"> </td>
<td> </td>
<td> </td>
<td align="center">Invoice Done By</td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
</table><br />
<?php } ?>
<?php
$cnt++;
$cnt2++;
if($cnt==$limit){
$cnt=0;
}
} ?>
</div>
</div>
<?php
} ?>
do not see such options in http://www.php.net/manual/en/function.printer-set-option.php
but you can have look around the functions here http://www.php.net/manual/en/ref.printer.php
printer_start_doc — Start a new document
printer_start_page — Start a new page

Expanding a table using checkbox

<script type='text/javascript' src='http://code.jquery.com/jquery-1.4.2.js'></script>
<script type='text/javascript'>
$(window).load(function () {
$('.varx').click(function () {
$(".text").toggle(this.checked);
$(".text1").toggle(this.checked);
$(".text2").toggle(this.checked);
$(".text3").toggle(this.checked);
});
});
</script>
<table border='1'>
<?php for ($i=1; $i<=5; $i++){ ?>
<tr>
<td>
<input type='checkbox' class='varx' />
</td>
<td>aaa</td>
<td>bbb</td>
<td>ccc</td>
<td></td>
<td></td>
<td></td>
<td></td>
<td>ddd</td>
<td>eee</td>
<td>fff</td>
</tr>
<tr>
<td class='text3' colspan='4' style='display:none'></td>
<td class='text3' style='display:none'>aaa</td>
<td class='text2' style='display:none'>bbb</td>
<td class='text1' style='display:none'>ccc</td>
<td class='text' style='display:none'>ddd</td>
<td class='text3' colspan='3' style='display:none'></td>
</tr>
<?php } ?>
</table>
This is running code, actually it is not a for ($i=1; $i<=5; $i++) it is foreach($items as $i). I decided to make it a for loop so that you can test it w/o database. My problem is, when I check one checkbox, all of the rows will expand and that is not right. What I need is when I check one checkbox, only one row only will expand.
Thanks for all of your help.
You only specified a class selector for the toggle commands. So of course it will toggle all the elements of this class.
Try this instead
$('.varx').click(function () {
var $theNextRow = $(this).parents('tr').eq(0).next();
$theNextRow.find(".text").toggle(this.checked);
$theNextRow.find(".text1").toggle(this.checked);
$theNextRow.find(".text2").toggle(this.checked);
$theNextRow.find(".text3").toggle(this.checked);
});
I have done complete solution bin for above issue. please check demo link as below:
Demo: http://codebins.com/bin/4ldqp7q
HTML
<table class="table" cellspacing="0" cellpadding="0">
<tr>
<th>
Choice
</th>
<th>
Col-1
</th>
<th>
Col-2
</th>
<th>
Col-3
</th>
<th>
Col-4
</th>
<th>
Col-5
</th>
<th>
Remove
</th>
</tr>
<tr>
<td>
<input type="checkbox" class="varx"/>
</td>
<td>
data-1
</td>
<td>
data-2
</td>
<td>
data-3
</td>
<td>
data-4
</td>
<td>
data-5
</td>
<td>
</td>
</tr>
<tr>
<td>
<input type="checkbox" class="varx"/>
</td>
<td>
data-21
</td>
<td>
data-22
</td>
<td>
data-23
</td>
<td>
data-24
</td>
<td>
data-25
</td>
<td>
</td>
</tr>
<tr>
<td>
<input type="checkbox" class="varx"/>
</td>
<td>
data-31
</td>
<td>
data-32
</td>
<td>
data-33
</td>
<td>
data-34
</td>
<td>
data-35
</td>
<td>
</td>
</tr>
</table>
jQuery
$(function() {
$(".varx").change(expandRow);
});
function expandRow() {
if ($(this).is(":checked")) {
var TrClone = $(this).closest("tr").clone();
$(TrClone).find("td:last").html("<input type='checkbox' class='remove'/>");
$(TrClone).insertAfter($(this).closest("tr"));
$(TrClone).find(".varx").removeAttr("checked");
$(TrClone).find(".varx").bind('change', expandRow);
$(TrClone).find(".remove").bind('change', removeRow);
}
}
function removeRow() {
if ($(this).is(":checked")) {
$(this).closest("tr").remove();
if ($(".table").find(".remove").length <= 0) {
$(".varx").removeAttr("checked");
}
}
}
CSS
.table{
width:70%;
border:1px solid #555;
}
.table th{
background:#dcacaa;
border-bottom:1px solid #555;
}
.table td{
text-align:center;
background:#c3cafd;
}
Demo: http://codebins.com/bin/4ldqp7q

Sum of numbers from dynamic inner text using jquery

I would like to get the total sum of values having class addition1:::
HTML CODE is
<tr >
<td> </td>
<td> </td>
<td> </td>
<td class="heading">Total Inr</td>
<td align="right" class="heading"><?php if($inr!='')echo co($inr);else echo "0.00";?> </td>
<td> </td>
<td class="heading">ROE</td>
<td class="heading" ><span class="addition1"><?php if($inr!='')echo co($inr);else echo "0.00";?> </span> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td class="heading">Total Usd</td>
<td align="right" class="heading"><?php if($usd!='')echo co($usd);else echo "0.00";?> </td>
<td> </td>
<td><input name="roe1" id="roe11" type="text" class="heading" value="1" style="width:50px" /></td>
<td class="heading1" style="font-family: Arial,Helvetica,sans-serif; font-size: 14px; font-variant: small-caps; font-weight: bold;">
<span class="addition1">
<?php if($usd!='')echo co($usd);else echo "0.00";?> </span>
</td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td class="heading">Total Gbp</td>
<td align="right" class="heading"><?php if($gbp!='')echo co($gbp);else echo "0.00";?></td>
<td> </td>
<td><input name="roe1" id="roe12" type="text" class="heading" value="1" style="width:50px" /></td>
<td class="heading2" style="font-family: Arial,Helvetica,sans-serif; font-size: 14px; font-variant: small-caps; font-weight: bold;">
<span class="addition1"><?php if($gbp!='')echo co($gbp);else echo "0.00";?></span>
</td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td class="heading">Total Eur</td>
<td align="right" class="heading"><?php if($eur!='')echo co($eur); else echo "0.00";?></td>
<td> </td>
<td><input name="roe1" id="roe13" type="text" class="heading" value="1" style="width:50px" /></td>
<td class="heading3" style="font-family: Arial,Helvetica,sans-serif; font-size: 14px; font-variant: small-caps; font-weight: bold;">
<span class="addition1"> <?php if($eur!='')echo co($eur); else echo "0.00";?></span>
</td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td class="heading">Total Other</td>
<td align="right" class="heading"><?php if($other!='')echo co($other);else echo "0.00";?></td>
<td> </td>
<td><input name="roe1" id="roe14" type="text" class="heading" value="1" style="width:50px" /></td>
<td class="heading4" style="font-family: Arial,Helvetica,sans-serif; font-size: 14px; font-variant: small-caps; font-weight: bold;">
<span class="addition1"><?php if($other!='')echo (co($other));else echo "0.00";?> </span>
</td>
<td> </td>
</tr>
Jquery Code is
$(document).ready(function() {
$('#tables tbody>tr>td>input.heading#roe13').change(function() {
var k = $('#roe13').val();
$('#tables tbody>tr>td.heading3').text(function(i,v) {
v= v.replace(/,/g, ''),
asANumber = +v;
x=Math.round(parseFloat(v*k)*100) / 100;
return x.toString().replace(/\B(?=(?:\d{3})+(?!\d))/g, ",");
});
});
$('#tables tbody>tr>td>input.heading#roe11').change(function() {
var k = $('#roe11').val();
$('#tables tbody>tr>td.heading1').text(function(i,v) {
v= v.replace(/,/g, ''),
asANumber = +v;
x1=Math.round(parseFloat(v*k)*100) / 100;
return x1.toString().replace(/\B(?=(?:\d{3})+(?!\d))/g, ",");
});
});
$('#tables tbody>tr>td>input.heading#roe12').change(function() {
var k = $('#roe12').val();
$('#tables tbody>tr>td.heading2').text(function(i,v) {
v= v.replace(/,/g, ''),
asANumber = +v;
x2=Math.round(parseFloat(v*k)*100) / 100;
return x2.toString().replace(/\B(?=(?:\d{3})+(?!\d))/g, ",");
});
});
$('#tables tbody>tr>td>input.heading#roe14').change(function() {
var k = $('#roe14').val();
$('#tables tbody>tr>td.heading4').text(function(i,v) {
v= v.replace(/,/g, ''),
asANumber = +v;
x3=Math.round(parseFloat(v*k)*100) / 100;
return x3.toString().replace(/\B(?=(?:\d{3})+(?!\d))/g, ",");
});
});
$('#tables tbody>tr').change(function() {
var sum = 0;
var regex = /\((\d+)\)/g;
$('span.addition1').each(function() {
matches = $(this).text().replace(/,/g, ''); alert(matches);
if( !isNaN( matches ) ){
sum += parseFloat(matches);
}
});
});
});
Class name in td can't be changed . I am trying to get the sum of values having class addition1. On running this code, 1 value is getting skipped, e.g. If I change a value say x1 then result generated due to x1 will be skipped in addition.
Please help me out.
Arrays in jquery are 0-based if you want the first value of matches use matches[0].
Don't put div's directly inside tr's. I'd recommend a span class="addition1" inside each of the td's and only round the floats you wish add.
This way you can parsefloat() first and then perform a NaN check after, stripping out all the regex stuff:
td code:
<td>..(<span class="addition1">1,230.0</span>)..</td>
jquery loop code:
$('span.addition1').each(function() {
var floatVal = parseFloat($(this).text().replace(/,/g,""));
if(!isNaN(floatVal)) {
sum += floatVal;
}
});
Use $(this).text() not .val().
$(this).val() refers to the value of the div.addition1, which does not have a value.
You are trying to nest td's inside a div which is not allowed for. If you cannot edit the TD's to give them a class you will have to use some other way of selecting them, like every eight TD or something similar.
HTML:
<tr >
<td> </td>
<td> </td>
<td> </td>
<td class="heading">Total Inr</td>
<td align="right" class="heading"><?php echo $inr!=''?co($inr):"0.00";?> </td>
<td> </td>
<td class="heading">ROE</td><div class="addition1">
<td class="heading" ><?php echo $inr!=''?co($inr):"0.00";?> </td></div>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td class="heading">Total Usd</td>
<td align="right" class="heading"><?php echo $usd!=''?co($usd):"0.00";?> </td>
<td> </td>
<td><input name="roe1" id="roe11" type="text" class="heading" value="1" style="width:50px" /></td>
<td class="heading1" style="font-family: Arial,Helvetica,sans-serif; font-size: 14px; font-variant: small-caps; font-weight: bold;">
<?php echo $usd!=''?co($usd):"0.00";?>
</td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td class="heading">Total Gbp</td>
<td align="right" class="heading"><?php echo $gbp!=''?co($gbp):"0.00";?></td>
<td> </td>
<td><input name="roe1" id="roe12" type="text" class="heading" value="1" style="width:50px" /></td>
<td class="heading2" style="font-family: Arial,Helvetica,sans-serif; font-size: 14px; font-variant: small-caps; font-weight: bold;">
<?php echo $gbp!=''?co($gbp):"0.00";?>
</td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td class="heading">Total Eur</td>
<td align="right" class="heading"><?php echo $eur!=''?co($eur):"0.00";?></td>
<td> </td>
<td><input name="roe1" id="roe13" type="text" class="heading" value="1" style="width:50px" /></td>
<td class="heading3" style="font-family: Arial,Helvetica,sans-serif; font-size: 14px; font-variant: small-caps; font-weight: bold;">
<?php echo $eur!=''?co($eur):"0.00";?>
</td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td class="heading">Total Other</td>
<td align="right" class="heading"><?php echo $other!=''?co($other):"0.00";?></td>
<td> </td>
<td><input name="roe1" id="roe14" type="text" class="heading" value="1" style="width:50px" /></td>
<td class="heading4" style="font-family: Arial,Helvetica,sans-serif; font-size: 14px; font-variant: small-caps; font-weight: bold;">
<?php echo $other!=''?co($other):"0.00";?>
</td>
<td> </td>
</tr>
Script:
$('table tr').change(function() {
var sum = 0;
$.each($('tr td input'), function() {
var nextCol = $(this).parent().next("td").text();
if( nextCol && ! isNaN( nextCol ) ){
sum += parseFloat(nextCol, 10);
}
});
alert(sum);
});
Just Addition:
$('table tr').change(function() {
var sum = 0;
$.each($('addition1'), function() {
var nextCol = $(this).text();
if( nextCol && ! isNaN( nextCol ) ){
sum += parseFloat(nextCol, 10);
}
});
alert(sum);
});

Printing website correctly

I am trying to make a website that reads from a csv file and render the data on the screen in a printable format (it is for printing tickets). The page creates 2 tickets per row and loops threw until it runs out of data. It all works perfectly and looks just the way i want it but, when i print it the 3rd row down has one of the rows of text move up onto the line above it. My question is how can i make it print the way it is seen on the screen and why would it screw up only the 3rd row when all rows are made with the same code.
Thanks
EDIT:
while (!feof($file_handle)){`
$csvText = fgetcsv($file_handle, 1024);
$username = $csvText[1];
$password = $csvText[2];
$profile = $csvText[3];
$daysValid = $csvText[4];
$expiry = $csvText[5];
if($pos == 0)
{
if($count == 5){
echo "<p><br /></p>";
$count = 0;
}else{
$count++;
}
echo "<div class='itemRow'>";
echo "<div class='left'>";
$pos = 1;
?>
<h4 class="centre">Internet Access Voucher</h4>
<img class="image" src="./icon.jpg" />
<div class="info">
<table>
<tr>
<td>
Username
</td>
</tr>
<tr>
<td>
Password
</td>
</tr>
<tr>
<td>
Profile
</td>
</tr>
<tr>
<td>
Valid for
</td>
</tr>
<tr>
<td>
Expiry date
</td>
</tr>
</table>
</div>
<div class="uniqueInfo">
<table>
<tr>
<td>
<?php echo $username;?>
</td>
</tr>
<tr>
<td>
<?php echo $password;?>
</td>
</tr>
<tr>
<td>
<?php echo $profile;?>
</td>
</tr>
<tr>
<td>
<?php echo $daysValid;?>
</td>
</tr>
<tr>
<td>
<?php echo $expiry;?>
</td>
</tr>
</table>
</div>
<p class="centre"><br />Please remember to disconnect to stop each session.</p>
</div>
<br />
<?php
} else {
?>
<div class="right">
<h4 class="centre">Internet Access Voucher</h4>
<img class="imageRight" src="./icon.jpg" />
<div class="infoRight">
<table>
<tr>
<td>
Username
</td>
</tr>
<tr>
<td>
Password
</td>
</tr>
<tr>
<td>
Profile
</td>
</tr>
<tr>
<td>
Valid for
</td>
</tr>
<tr>
<td>
Expiry date
</td>
</tr>
</table>
</div>
<div class="uniqueInfoRight">
<table>
<tr>
<td>
<?php echo $username;?>
</td>
</tr>
<tr>
<td>
<?php echo $password;?>
</td>
</tr>
<tr>
<td>
<?php echo $profile;?>
</td>
</tr>
<tr>
<td>
<?php echo $daysValid;?>
</td>
</tr>
<tr>
<td>
<?php echo $expiry;?>
</td>
</tr>
</table>
</div>
<p class="centre"><br />Please remember to disconnect to stop each session.</p>
</div>
</div>
<?php
$pos = 0;
}
}
?>
CSS
.centre
{
text-align:center;
}
.itemRow
{
position:relative;
top:0px;
}
.left
{
width:500px;
position:relative;
font-family:Comic Sans, Comic sans MS, cursive;
/*border-style:solid;
border-width:1px;*/
}
.right
{
width:500px;
position:absolute;
left:600px;
top:-20px;
font-family:Comic Sans, Comic sans MS, cursive;
/*(border-style:solid;
border-width:1px;*/
}
.image
{
position:absolute;
top:70px;
}
.info
{
position:relative;
left:63px;
}
.uniqueInfo
{
position:absolute;
left:250px;
top:42px;
}
.infoRight
{
position:relative;
left:63px;
top:0px;
}
.uniqueInfoRight
{
position:absolute;
left:250px;
top:65px;
}
.imageRight
{
position:absolute;
top:90px;
}
I suspect this might be the problem:
if($count == 5){
echo "<p><br /></p>";
You have 2 per row, and increment $count after every ticket. So, $count = 5 would be after the fourth ticket, or when the third row starts. A sample HTML page would give me a better idea of what's going on exactly, but I'd suggest doing something like
<br style="clear: both;" />
between the rows to split them cleanly. So before ticket 3 and 5 ($count = 3 and $count = 5).

Categories