show in a pdf only what is shown in a table

0

I would like to know if it is possible to show in a pdf what is on a page of a table and how to do it. For example: If I have 100 data and I have a page that shows me 10 in 10 and I select page 3 I would be showing from 21 to 30; by showing the pdf I want you to only show me the data that is on that page.

If I change the page, show in a pdf the data of that page only.

    
asked by jota 27.10.2016 в 17:19
source

1 answer

1

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

    
answered by 27.10.2016 в 19:21