Search code examples
javascripthtmlangulartypescriptpdfmake

associate a column of another array on pdfmake


In my project I want to associate the values of an array other than the one present in the first two columns. It's possible? (The number of value of partialPrice is identical to the number of code present). I've tried this but it doesn't work:

interv: Intervention[]
partialPrice = []
{
          table: {
            headerRows: 1,
            widths: ['auto', 'auto', 'auto'],
            body: [
              ['Code', 'Description', 'Price'],
              ...this.interv.map(intervObj => 
                  [intervObj.intervention.code, intervObj.intervention.description],
                  this.partialPrice.map(price =>
                    [price])
              )
            ]
          }
        },

Solution

  • So, you need to extract the element from the partialPrice array depending on the current index of the map() that you are using on the interv array. So, this should work:

      body: [
              ['Code', 'Description', 'Price'],
              ...this.interv.map((intervObj, index) => 
                  [intervObj.intervention.code, intervObj.intervention.description, partialPrice[index]]
              )
            ]