Datatable + PDF
Datatable + PDF
Hello, I'm Using datatable to show a list of approved or reproved applications, now it does it just fine, BUT I'd like to put a PDF button to the table so, it generates the pdf with the current content of the table, and I'm trying to do it by add the pertinent code u give to my jquery instruction, but it does not work, I'd like to know how to make it work please...
Data table script
$(document).ready(function(){
var datatable = $('#mytable').DataTable({
buttons: [
{
extend: 'pdfHtml5',
orientation: 'landscape',
pageSize: 'LEGAL'
}
],
"ajax": {
"url": "../procesos/motor_funciones.php",
"type": "POST",
"data" : {
"accion" : "mostrar_proceso_ret", //nombre que recibe el switch
}
},
"language": {
"processing": "No hay registros en el histórico",
"loadingRecords": " ",
"lengthMenu": "Mostrando _MENU_ registros por página",
"zeroRecords": "Nada econtrado - Perdón",
"info": "Mostrando página _PAGE_ de _PAGES_",
"infoEmpty": "No hay registros disponibles",
"infoFiltered": "(filtrado de _MAX_ registros totales)" ,
"search": "Búsqueda"
},
"sAjaxDataProp": "",
"processing": true,
//"pageLength": 20,
// "serverSide": true,
columns:
[
{data:"cedula"},
{data:"numero"},
{data:"aval"},
{data:"razon"},
{data:"link"}
]
});
});
the "motor_funciones.php call
case 'mostrar_proceso_ret':
$array = $objRetiros->mostrar_proceso('Retiro',$bandera,$nivel);
echo $array;
break;
The "mostrar_retiros" function
$query="SELECT * FROM solicitudes_ret WHERE (proceso LIKE '$proceso%')";
$result=$this->conn->Execute($query);
$j=0;
while(!$result->EOF)
{
for ($i=0, $max=$result->FieldCount(); $i<$max; $i++)
{
$proceso=$result->fields['proceso'];
$cedula=$result->fields['cedula'];
$numero_sol=$result->fields['numero_soli'];
$exp=$result->fields['exp'];
$razon = $result->fields['razon'];
if($exp == '-1')
{
$aval = 'No avalado';
}
else
{
$aval = 'Avalado';
}
//$aval2 = base64_encode($aval);
$cedula2=base64_encode($cedula);
$numero_sol2=base64_encode($numero_sol);
$proceso=base64_encode($proceso);
$exp=base64_encode($exp);
$link="<a href=\"evaluar.php?proceso=".$proceso."&exp=".$exp."&id=".$cedula2."&numero=".$numero_sol2."\" target='_blank'>Evaluar</a>";
$result->MoveNext();
break;
}
$data[$j]=array("cedula"=>$cedula,
"numero"=> $numero_sol,
"aval"=> $aval,
"razon"=> $razon,
"link"=>$link);
$j++;
}
header('Content-type: application/json');
return json_encode($data);
It works perfectly but the PDF button I can't see it, I'll appreciate any help, thanks in advance
This question has accepted answers - jump to:
Answers
Have you included the pdfmake library? It is required for the
pdfHtml5
button type.If that isn't the issue, please link to a test page showing the issue, per the forum rules.
Thanks,
Allan
Hi allan, My problem is that I'm working locally, and I don't have a domain to upload this and make it visible for u all , I'm doing my thesys to get my degree, so I'm trying to pull this off however I can, and I really like datatable, actually I had bad problems back then when I was trying to first make it work xD, but, I wasn't putting those librarys on my project, but still putting them there, is not showing the PDF I'm really sad about that >.<
here's my "improved" code >.<
head
Table with javascript >.<
the motor_funciones, and mostrar_procesos functions, are still the same... If u could help I'd really appreciate it, like really really, I don't see the PDF button it shows in this: "https://datatables.net/extensions/buttons/examples/html5/pdfImage.html" example, I fon't know why...
and this is how I see the table, with no freaking PDF button >.<
I did it! ty for ur time anyways allan! now I'm trying to customize the PDF xD is harder than it looks
Thanks for posting back - good to hear you've got it working.
Allan
Now, Can I disturb you a lil more? (and I don't mean go down with the sickness) do u have an example on HOW to customize the pdf, using the js script? I saw u had a image in your example, but I can't seem to put a local image file in there, and the pdfmake page is not helping me, that's why I ask u, ty in advance
You can images if they're in base64 format , you can convert them here http://dataurl.net/#dataurlmaker
Hi mohammed yes! ty very much for ur answer, now the only two things left, are, 1-. make the PDF table centered (it shows up at left) and 2.- delimitate how many and wich columns I want to put in the PDF, in other words, If i have 5 colums in my datatable; name, ID, date, reason and actions, I want to tell the PDFmak, hey you dont show the Actions column in the PDF , right now my js code for the datatable and pdf make looks like this:
I putted the table too so u can see >.<
ty in advance!