Click here to Skip to main content
15,884,177 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Hello,

My table has two header rows, DataTable is showing bother header rows but not exported to pdf please help.

My table is:
PHP
<table id="example" class="table table-striped table-sm table-bordered nowrap" style="width:100%">
 <thead>
	<tr><th colspan="2"><?php if(isset($session)){ echo $session; } ?> - <?php if(isset($class)){ echo $class; } ?>
			- <?php if(isset($section)){ echo $section; } ?></th></tr>
		<tr>
			<th class="text-primary">Roll #</th>
			<th class="text-primary">Student Name</th>
		</tr>
	</thead>
	<?php if(isset($rows)) { ?>
	<tbody>
		<?php foreach($rows as $row) { ?>		  
			<tr>
				<td><?=$row['rollno'];?></td>
				<td><?=$row['studentname'];?></td>
			</tr>
	  <?php  } ?>
	</tbody>
	<?php  } ?>
</table>


DataTable Image

PDF Output
Please help, thanks in advance.

What I have tried:

JavaScript
$('#example').DataTable({
        header: true,
        dom: 'Blfrtip',
        search: true,
            iDisplayLength: 10,
            lengthMenu: [
            [ 10, 25, 50,100, -1 ],
            [ '10 rows', '25 rows', '50 rows','100 rows', 'Show all' ]
            ],
            buttons: [
            'copyHtml5',
            'excelHtml5',
            'csvHtml5',
            {
                extend: 'pdfHtml5',
                orientation: 'landscape',
                pageSize: 'LEGAL'
            }
            ]
         });
Posted
Updated 20-Aug-22 2:35am
v4

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900