Sunday 15 July 2012

javascript - Building table dynamically with PDFMake -



javascript - Building table dynamically with PDFMake -

i'm working pdfmake generate pdf javascript. i'm trying build table dynamically not works ,this attempt

class="lang-js prettyprint-override">$.ajax({ type: "post", url: myurl, success:function(data){ /* info has format : *[{"peaje":"peaje 1","ruta":"ruta 1","fechacruce":"2014-10-18","hora":"15:42","valor":"5000"},{"peaje":"peaje 1","ruta":"ruta 1","fechacruce":"2014-10-18","hora":"14:21","valor":"7000"},{"peaje":"peaje 1","ruta":"ruta 1","fechacruce":"2014-09-19","hora":"11:58","valor":"17000"}] */ var peajes = json.parse( info ); var body = []; var titulos = new array( 'peaje', 'ruta', 'fecha cruce', 'hora', 'valor' ); body.push( titulos ); (key in peajes) { if (peajes.hasownproperty(key)) { var peaje = peajes[key]; var fila = new array(); fila.push( peaje.peaje.tostring() ); fila.push( peaje.ruta.tostring() ); fila.push( peaje.fechacruce.tostring() ); fila.push( peaje.hora.tostring() ); fila.push( peaje.valor.tostring() ); body.push(fila); } } console.log( body ); var docdefinition = { content: [ { table: { headerrows: 1, widths: [ '*', 'auto', 100, '*' ], body: body } }] };//end docdefinition pdfmake.createpdf(docdefinition).open(); }//end success });

this illustration of library http://pdfmake.org/#/gettingstarted

i don't know doing wrong?

you should create array of culumn name & value

class="snippet-code-js lang-js prettyprint-override">var column = []; column.push({ text: 'a', style: 'tableheader'}); column.push({ text: 'b', style: 'tableheader'}); var value = []; value.push({ text: 'asda', style: 'tableheader'}); value.push({ text: 'bsa', style: 'tableheader'});

when create table, should this.

class="snippet-code-js lang-js prettyprint-override">table: { headerrows: 1, body: [ column, value ] }

javascript pdf-generation pdfmake

No comments:

Post a Comment