Home:ALL Converter>Dynamic tables with pdfmake and firebase data

Dynamic tables with pdfmake and firebase data

Ask Time:2018-12-23T00:42:38         Author:cssler

Json Formatter

I´m trying to create a dynamic table with pdfmake and Angular5/Ionic3. As table data I need some data from firebase snapshot. So in case I have an observable.

What I tried

Subscribing observable and save data

this.streetDetailData
      .take(1)
      .subscribe(data => {
        bodyData.push(data);
      });

pdfmake definition

content: [
    { text: `${this.sStreet.street}${this.sStreet.parentPLZ ? ', ' +  this.sStreet.parentPLZ : ''}, ${this.sStreet.parentCountry}`, style: 'header' },
    { text: moment().format('LL'), style: 'date'},

    this.table(bodyData, ['number', 'status'])

  ],

table function

table(data, columns) {
    return {
      table: {
        headerRows: 1,
        body: this.buildTableBody(data, columns)
      }
    };
  }

buldTableBody function

buildTableBody(data, columns) {

    let body = [];

    body.push(columns);

    data.forEach((row) => {
      console.log(row);

      let dataRow = [];

      columns.forEach(function(column) {
        dataRow.push(row[column].toString());
      });

      body.push(dataRow);
    });

    return body;
  }

But no chance...I´m always getting an empty result... Where´s the error?

That´s what I see in the generated PDF:

enter image description here

Author:cssler,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/53897494/dynamic-tables-with-pdfmake-and-firebase-data
yy