To export to pdf I use the library dompdf, In your case you have two options, if the table has a javascript you can find out if it is possible to obtain from the dataSource with the current rows, with which you can send the data in in one variable per GET or POST that the export.php file receives.
require_once(dirname(__FILE__) . "/../../../phpModules/dompdf/dompdf_config.inc.php");
//en caso de venir en un directamente array un desde Javascript
$table=$_GET['table'];
//en caso de que envies la informacion como JSON.Stringfy desde Javascript con esto obtienes los datos en un array
$table=json_decode($_GET['table'],true);
$paginaPDF="<html>
<head>
<title>Mi reporte</title>
</head>
<body>
<div class='cabecera'>
aca puedes incluir el logo y todos los detalles de cabecera
</div>
";
$htmlDeTabla='<table class="myTable">
<tr>
<td>Columna A</td><td>Columna B</td><td>Columna C</td>
</tr>';
foreach($table as $data){
$htmlDeTabla.'<tr>
<td>'.$data['ColumnaA'].'</td>
<td>'.$data['ColumnaB'].'</td>
<td>'.$data['ColumnaC'].'</td>
</tr>';
}
$paginaPDF.=$htmlDeTabla.'</body></html>';
//Se codifica el PDF
$dompdf = new \DOMPDF();
$dompdf->load_html($html);
$dompdf->set_paper('letter');//Tamaño de papel
$dompdf->render();
$base64 = base64_encode($dompdf->output());
//Mostrar el pdf en el navegador
echo '<iframe width="100%" height="100%" src="data:application/pdf;base64,' . $base64 . '" ></iframe>';
If you can not get the data from the current view, the other option is the current page number, with which you would have to do the calculations for the paging records and launch the query to the database.
$paginaActual=$_GET['page_num'];//El numero de pagina actual del Grid
$itemsPorPagina=100; //
$desde=(int)$paginaActual*$itemsPorPagina;
$query='select * from my table LIMIT '.$itemsPorPagina.' OFFSET '.$desde;
$result=MyDabase->Executequery($query); //Cualquier metodo que ejecute la consulta
$htmlDeTabla='<table class="myTable">
<tr>
<td>Columna A</td><td>Columna B</td><td>Columna C</td>
</tr>';
foreach($result as $data){
$htmlDeTabla.'<tr>
<td>'.$data['ColumnaA'].'</td>
<td>'.$data['ColumnaB'].'</td>
<td>'.$data['ColumnaC'].'</td>
</tr>';
}
// Lo demas igual al anterior
The problem is not in exporting to pdf, but in that you can know these two data, according to some function of the Grid