# Conditionally Right Align Selected Columns in pdfmake Both Column headers and Column contents

**URL:** <https://discourse.nodered.org/t/conditionally-right-align-selected-columns-in-pdfmake-both-column-headers-and-column-contents/68131>\
**Category:** General\
**Created:** [23 September 2022 12:12 UTC](https://discourse.nodered.org/t/conditionally-right-align-selected-columns-in-pdfmake-both-column-headers-and-column-contents/68131 "2022-09-23T12:12:20Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![smanjunath211](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/smanjunath211/32/95742_2.png) [@smanjunath211](https://discourse.nodered.org/u/smanjunath211)\
**Post date:** [23 September 2022 12:12 UTC](https://discourse.nodered.org/t/conditionally-right-align-selected-columns-in-pdfmake-both-column-headers-and-column-contents/68131/1 "2022-09-23T12:12:20Z")

</div>

Hi,  
I have a working solution for creating a pdf from a series of MySQL query outputs into a dynamic table.  
now the issue is i don't know how to right align few selected columns (that have numbers.).  
Since the contents are coming from a dynamic source (from a query output).

```auto
// Table 1
        
        {
                        style: 'tableExample',
        
            table: {
                headerRows: 1,
                widths: [200, 80],
                body: [
                    Object.keys(msg.payload.query0[0]).map(key => { return { text: key, style: 'tableHeader' } }),
                    ...msg.payload.query0.map(obj => Object.values(obj))
                ]
            },
            layout: 'lightHorizontalLines'
        },

```

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/b/e/be7d2b5e93afef9d2e101bed02ca2d363cef3c0b.png)

the below code snippet works for static data

```auto
				body: [
		            [{text:'100', alignment:'right'}]

```

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/9/e/9e96aed9f7ed73c53766ee43b267fc0b801f7b48.png)

---

<div class="post-metadata">

**Author:** ![UnborN](https://avatars.discourse-cdn.com/v4/letter/u/4491bb/32.png) [@UnborN](https://discourse.nodered.org/u/UnborN)\
**Post date:** [27 September 2022 17:53 UTC](https://discourse.nodered.org/t/conditionally-right-align-selected-columns-in-pdfmake-both-column-headers-and-column-contents/68131/2 "2022-09-27T17:53:30Z")

</div>

> [@smanjunath211](#):
>
> ` style: 'tableExample',`

from your code i see that you have already applied a style called `tableExample` to the table  
so based on the [pdfmake documenation](https://pdfmake.github.io/docs/0.1/document-definition-object/styling/) you can use that to align the column

Im providing the whole code example so its easier for you to see where the style is used

```javascript
let date = new Date().toLocaleString('en-GB', { timeZone: 'Asia/Nicosia' })

let tableData = {

    pageSize: 'A4',
    pageOrientation: 'landscape',
    content: [

        { text: 'This is my Sqlite Table from Query 1', fontSize: 14, bold: true, margin: [0, 20, 0, 0] },
        { text: `Created:${date}`, fontSize: 8, bold: true, margin: [0, 5, 0, 8] },
        {
            style: 'tableExample',
            table: {
                headerRows: 1,
                body: [
                    Object.keys(msg.payload.query1[0]).map(key => { return { text: key, style: 'tableHeader' } }),
                    ...msg.payload.query1.map(obj => Object.values(obj))
                ]
            },
            layout: 'lightHorizontalLines'
        },

        { text: 'This is my Sqlite Table from Query 2', fontSize: 14, bold: true, margin: [0, 20, 0, 0], pageBreak: 'before' },
        { text: `Created:${date}`, fontSize: 8, bold: true, margin: [0, 5, 0, 8] },

        {
            style: 'tableExample',
            table: {
                headerRows: 1,
                body: [
                    Object.keys(msg.payload.query2[0]).map(key => { return { text: key, style: 'tableHeader' } }),
                    ...msg.payload.query2.map(obj => Object.values(obj))
                ]
            },
            layout: 'lightHorizontalLines'
        }
    ],
    styles: {
        header: {
            fontSize: 18,
            bold: true,
            margin: [0, 0, 0, 10]
        },
        subheader: {
            fontSize: 16,
            bold: true,
            margin: [0, 10, 0, 5]
        },
        tableExample: {
            margin: [0, 5, 0, 15],
            alignment: 'right' // HERE
        },
        tableHeader: {
            bold: true,
            fontSize: 13,
            color: 'black'
        }
    },
    defaultStyle: {
        // alignment: 'justify'
    }

};

msg.payload = tableData;

return msg;

```

---

<div class="post-metadata">

**Author:** ![smanjunath211](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/smanjunath211/32/95742_2.png) [@smanjunath211](https://discourse.nodered.org/u/smanjunath211)\
**Post date:** [28 September 2022 00:49 UTC](https://discourse.nodered.org/t/conditionally-right-align-selected-columns-in-pdfmake-both-column-headers-and-column-contents/68131/3 "2022-09-28T00:49:22Z")

</div>

> [@UnborN](#):
>
> ```auto
> ,
> alignment: 'right' // HERE
> 
> ```

i did check this option, but this gives the 'entire table' right aligned,

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/e/b/eb884516bae24f50ae979c1ba95c3668ee1b15d8.png)

as requested in my original post, i want only certain columns which have numbers second column in this example, to be right aligned.

> [@smanjunath211](#):
>
> i don't know how to right align few selected columns (that have numbers.).

for static data it is possible as i am able to do that for every column selectively. but for a table generated by a statement like this i don't know how.

> [@smanjunath211](#):
>
> ```auto
> body: [
> Object.keys(msg.payload.query0[0]).map(key => { return { text: key, style: 'tableHeader' } }),
> ...msg.payload.query0.map(obj => Object.values(obj))
> ]
> 
> ```

thanks.

---

<div class="post-metadata">

**Author:** ![smanjunath211](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/smanjunath211/32/95742_2.png) [@smanjunath211](https://discourse.nodered.org/u/smanjunath211)\
**Post date:** [28 September 2022 01:07 UTC](https://discourse.nodered.org/t/conditionally-right-align-selected-columns-in-pdfmake-both-column-headers-and-column-contents/68131/4 "2022-09-28T01:07:40Z")

</div>

> [@smanjunath211](#):
>
> ` widths: [200, 80],`

I am able to make individual column's width as per my requirement, by above code, i wanted a similar way to do alignment of individual columns as per my requirement.

I just tried to copy the same syntax which worked for individual column's width setting, to alignment, but no effect, didn't throw an error either.

```auto
{
                        style: 'tableExample',
        
            table: {
                headerRows: 1,
                alignment: ['left', 'right'], // HERE
                widths: [200, 80],
                body: [
                    Object.keys(msg.payload.query1a[0]).map(key => { return { text: key, style: 'tableHeader' } }),
                    ...msg.payload.query1a.map(obj => Object.values(obj))
                ]
            },
            layout: 'lightHorizontalLines',
         },

```

---

<div class="post-metadata">

**Author:** ![UnborN](https://avatars.discourse-cdn.com/v4/letter/u/4491bb/32.png) [@UnborN](https://discourse.nodered.org/u/UnborN)\
**Post date:** [28 September 2022 03:49 UTC](https://discourse.nodered.org/t/conditionally-right-align-selected-columns-in-pdfmake-both-column-headers-and-column-contents/68131/5 "2022-09-28T03:49:28Z")

</div>

> [@smanjunath211](#):
>
> as requested in my original post, i want only certain columns which have numbers

i see .. thats a bit more complicated  
you need to check if the value is Number with isNaN and return an object with `text` and `alignment` accordingly

> **Try this sample**
>
> ```javascript
> let date = new Date().toLocaleString('en-GB', { timeZone: 'Asia/Nicosia' })
> 
> let query1Data = []
> 
> msg.payload.query1.forEach(obj => {
> query1Data.push(Object.entries(obj).map( ([key, value]) => { return !isNaN(value) ? { text: value, alignment: 'right' } : { text: value, alignment: 'left' }}))    
> })
> 
> let query2Data = []
> 
> msg.payload.query2.forEach(obj => {
> query2Data.push(Object.entries(obj).map( ([key, value]) => { return !isNaN(value) ? { text: value, alignment: 'right' } : { text: value, alignment: 'left' }}))    
> })
> 
> node.warn(query2Data)
> 
> let tableData = {
> 
> pageSize: 'A4',
> pageOrientation: 'landscape',
> content: [
> 
> { text: 'This is my Sqlite Table from Query 1', fontSize: 14, bold: true, margin: [0, 20, 0, 0] },
> { text: `Created:${date}`, fontSize: 8, bold: true, margin: [0, 5, 0, 8] },
> {
> style: 'tableExample',
> table: {
> headerRows: 1,
> body: [
> Object.keys(msg.payload.query1[0]).map(key => { return { text: key, style: 'tableHeader' } }),
> ...query1Data
> ]
> },
> layout: 'lightHorizontalLines'
> },
> 
> { text: 'This is my Sqlite Table from Query 2', fontSize: 14, bold: true, margin: [0, 20, 0, 0], pageBreak: 'before' },
> { text: `Created:${date}`, fontSize: 8, bold: true, margin: [0, 5, 0, 8] },
> 
> {
> style: 'tableExample',
> table: {
> headerRows: 1,
> body: [
> Object.keys(msg.payload.query2[0]).map(key => { return { text: key, style: 'tableHeader' } }),
> ...query2Data,
> ]
> },
> layout: 'lightHorizontalLines'
> }
> ],
> styles: {
> header: {
> fontSize: 18,
> bold: true,
> margin: [0, 0, 0, 10]
> },
> subheader: {
> fontSize: 16,
> bold: true,
> margin: [0, 10, 0, 5]
> },
> tableExample: {
> margin: [0, 5, 0, 15],
> // alignment: 'right'
> },
> tableHeader: {
> bold: true,
> fontSize: 13,
> color: 'black'
> }
> },
> defaultStyle: {
> // alignment: 'justify'
> }
> 
> };
> 
> msg.payload = tableData;
> 
> return msg;
> 
> ```

---

<div class="post-metadata">

**Author:** ![smanjunath211](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/smanjunath211/32/95742_2.png) [@smanjunath211](https://discourse.nodered.org/u/smanjunath211)\
**Post date:** [28 September 2022 11:54 UTC](https://discourse.nodered.org/t/conditionally-right-align-selected-columns-in-pdfmake-both-column-headers-and-column-contents/68131/6 "2022-09-28T11:54:21Z")

</div>

Perfect!. You are a genius! 👍

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/c/5/c5de80321d5517b225a975497b6a8b03dcfc171d.png)

Now I have to try and adapt this to my code which has several tables in it and i am struggling to fix it , i am continuously working on it without success. let me give it some more try.

---

<div class="post-metadata">

**Author:** ![smanjunath211](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/smanjunath211/32/95742_2.png) [@smanjunath211](https://discourse.nodered.org/u/smanjunath211)\
**Post date:** [29 September 2022 01:59 UTC](https://discourse.nodered.org/t/conditionally-right-align-selected-columns-in-pdfmake-both-column-headers-and-column-contents/68131/7 "2022-09-29T01:59:53Z")

</div>

Done. successfully adapted to my table.

---

<div class="post-metadata">

**Author:** ![smanjunath211](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/smanjunath211/32/95742_2.png) [@smanjunath211](https://discourse.nodered.org/u/smanjunath211)\
**Post date:** [29 September 2022 02:30 UTC](https://discourse.nodered.org/t/conditionally-right-align-selected-columns-in-pdfmake-both-column-headers-and-column-contents/68131/8 "2022-09-29T02:30:08Z")

</div>

How do we do the same for column headers ?

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/d/2/d2d034efa4ee09b0a290ebf1d10ead39539f8c3a.png)

my function node

```auto
[{"id":"36c750e217537997","type":"function","z":"281cdefb6b284529","name":"data to pdf","func":"///\nlet query0Data = []\nmsg.payload.query0.forEach(obj => {\n query0Data.push(Object.entries(obj).map(([key, value]) => { return !isNaN(value) ? { text: value, alignment: 'right' } : { text: value, alignment: 'left' } }))\n })\n\nlet query1aData = []\nmsg.payload.query1a.forEach(obj => {\n query1aData.push(Object.entries(obj).map(([key, value]) => { return !isNaN(value) ? { text: value, alignment: 'right' } : { text: value, alignment: 'left' } }))\n})\n\nlet query1bData = []\nmsg.payload.query1b.forEach(obj => {\n query1bData.push(Object.entries(obj).map(([key, value]) => { return !isNaN(value) ? { text: value, alignment: 'right' } : { text: value, alignment: 'left' } }))\n})\n\nlet querys5Data = []\nmsg.payload.querys5.forEach(obj => {\n querys5Data.push(Object.entries(obj).map(([key, value]) => { return !isNaN(value) ? { text: value, alignment: 'right' } : { text: value, alignment: 'left' } }))\n})\n\nlet querys6Data = []\nmsg.payload.querys6.forEach(obj => {\n querys6Data.push(Object.entries(obj).map(([key, value]) => { return !isNaN(value) ? { text: value, alignment: 'right' } : { text: value, alignment: 'left' } }))\n})\n\nlet querys7Data = []\nmsg.payload.querys7.forEach(obj => {\n querys7Data.push(Object.entries(obj).map(([key, value]) => { return !isNaN(value) ? { text: value, alignment: 'right' } : { text: value, alignment: 'left' } }))\n})\n\nlet querys8Data = []\nmsg.payload.querys8.forEach(obj => {\n querys8Data.push(Object.entries(obj).map(([key, value]) => { return !isNaN(value) ? { text: value, alignment: 'right' } : { text: value, alignment: 'left' } }))\n})\n\nlet querys9Data = []\nmsg.payload.querys9.forEach(obj => {\n querys9Data.push(Object.entries(obj).map(([key, value]) => { return !isNaN(value) ? { text: value, alignment: 'right' } : { text: value, alignment: 'left' } }))\n})\n\nlet querys10Data = []\nmsg.payload.querys10.forEach(obj => {\n querys10Data.push(Object.entries(obj).map(([key, value]) => { return !isNaN(value) ? { text: value, alignment: 'right' } : { text: value, alignment: 'left' } }))\n})\n\n\n///\n\n\n\nlet tableData = {\n\n// pageSize: 'a3',\n pageSize: {\n width: 1000,\n height: 'auto'\n },\n pageOrientation: 'portrait',\n content: [\n { text: flow.get(\"pdf_header2\"), fontSize: 20, bold: true, alignment: 'center', color: 'green', margin: [12, 0, 12, 0] },\n { text: '', fontSize: 20, bold: true, margin: [0, 0, 0, 0] },\n\n\n{\n\t\t\talignment: 'left',\n\t\t\tcolumns: [\n\n { text: flow.get(\"m\"), fontSize: 14, bold: true, margin: [12, 5, 12, 5] },\n { text: flow.get(\"m1a\"), fontSize: 14, bold: true, margin: [12, 5, 12, 5] },\n { text: flow.get(\"m1b\"), fontSize: 14, bold: true, margin: [12, 5, 12, 5] },\n\n ]},\n \n{\t\t\talignment: 'justify',\n\t\t\tcolumns: [\n\n// Table 1\n\n\n {\n style: 'tableExample1',\n \n table: {\n headerRows: 1,\n widths: [200, 53],\n body: [\n Object.keys(msg.payload.query0[0]).map(key => { return { text: key, style: 'tableHeader' } }),\n ...query0Data\n ]\n },\n layout: 'lightHorizontalLines'\n },\n// Table 2\n\n\n {\n style: 'tableExample',\n \n table: {\n headerRows: 1,\n widths: [200, 53],\n body: [\n Object.keys(msg.payload.query1a[0]).map(key => { return { text: key, style: 'tableHeader' } }),\n ...query1aData\n ]\n },\n layout: 'lightHorizontalLines',\n },\n\n// Table 3\n\n {\n style: 'tableExample',\n\n table: {\n headerRows: 1,\n widths: [200, 53],\n body: [\n Object.keys(msg.payload.query1b[0]).map(key => { return { text: key, style: 'tableHeader' } }),\n ...query1bData\n ]\n },\n layout: 'lightHorizontalLines'\n },\n \n ]},\n \n{ text: '--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------', fontSize: 10, bold: false, color: 'orange', margin: [0, 0, 0, 5] },\n { text: 'TOP 10 DOWNTIME REASONS FOR THE DAY SHIFT WISE', fontSize: 14,alignment:'centre', bold: false, color: 'BLUE', margin: [0, 0, 0, 5] },\n\n//\n\n {\n\t\t\talignment: 'center',\n\t\t\tcolumns: [\n \n \n { text: flow.get(\"top10dta\"), fontSize: 14, bold: true, color: 'black', margin: [0, 0, 0, 5] },\n { text: flow.get(\"top10dtb\"), fontSize: 14, bold: true, color: 'black', margin: [0, 0, 0, 5] },\n { text: flow.get(\"top10dtc\"), fontSize: 14, bold: true, color: 'black', margin: [0, 0, 0, 5] },\n \n ]},\n \n {\n\t\t\talignment: 'centre',\n\t\t\tcolumns: [\n \n {\n style: 'tableExample',\n table: {\n headerRows: 1,\n widths: [150, 100],\n body: [\n Object.keys(msg.payload.querys5[0]).map(key => { return { text: key, style: 'tableHeader' } }),\n ...querys5Data\n ]\n },\n layout: 'lightHorizontalLines'\n },\n {\n style: 'tableExample',\n table: {\n headerRows: 1,\n widths: [150, 100],\n body: [\n Object.keys(msg.payload.querys6[0]).map(key => { return { text: key, style: 'tableHeader' } }),\n ...querys6Data\n ]\n },\n layout: 'lightHorizontalLines'\n },\n {\n style: 'tableExample',\n table: {\n headerRows: 1,\n widths: [150, 100],\n body: [\n Object.keys(msg.payload.querys7[0]).map(key => { return { text: key, style: 'tableHeader' } }),\n ...querys7Data\n ]\n },\n layout: 'lightHorizontalLines'\n }\n ]},\n \n\n{ text: '--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------', fontSize: 10, bold: false, color: 'orange', margin: [0, 0, 0, 5] },\n { text: 'MACHINE WISE DOWNTIMES FOR THE DAY SHIFT WISE', fontSize: 14,alignment:'centre', bold: false, color: 'BLUE', margin: [0, 0, 0, 5] },\n\n \n {\n\t\t\talignment: 'centre',\n\t\t\tcolumns: [\n \n \n {\n style: 'tableExample',\n table: {\n headerRows: 1,\n widths: [150, 100],\n body: [\n Object.keys(msg.payload.querys8[0]).map(key => { return { text: key, style: 'tableHeader' } }),\n ...querys8Data\n ]\n },\n layout: 'lightHorizontalLines'\n },\n {\n style: 'tableExample',\n table: {\n headerRows: 1,\n widths: [150, 100],\n body: [\n Object.keys(msg.payload.querys9[0]).map(key => { return { text: key, style: 'tableHeader' } }),\n ...querys9Data\n ]\n },\n layout: 'lightHorizontalLines'\n },{\n style: 'tableExample',\n table: {\n headerRows: 1,\n widths: [150, 100],\n body: [\n Object.keys(msg.payload.querys10[0]).map(key => { return { text: key, style: 'tableHeader' } }),\n ...querys10Data\n ]\n },\n layout: 'lightHorizontalLines'\n }\n \n \n \n ]},\n \n\n\n// Table 3\n { text: flow.get(\"m00\"), fontSize: 14, bold: true, margin: [12, 5, 12, 5] },\n \n {\n style: 'tableExample',\n table: {\n headerRows: 1,\n widths: [50, 30, 80, 80, 50, 240, 240],\n body: [\n Object.keys(msg.payload.query2[0]).map(key => { return { text: key, style: 'tableHeader' } }),\n ...msg.payload.query2.map(obj => Object.values(obj))\n ]\n },\n layout: 'lightHorizontalLines'\n },\n// Table 4\n { text: flow.get(\"m01\"), fontSize: 14, bold: true, margin: [12, 5, 12, 5] },\n {\n style: 'tableExample',\n table: {\n headerRows: 1,\n widths: [50, 30, 80, 80, 50, 240, 240],\n body: [\n Object.keys(msg.payload.query3[0]).map(key => { return { text: key, style: 'tableHeader' } }),\n ...msg.payload.query3.map(obj => Object.values(obj))\n ]\n },\n layout: 'lightHorizontalLines'\n },\n// Table 5\n { text: flow.get(\"m02\"), fontSize: 14, bold: true, margin: [12, 5, 12, 5] },\n {\n style: 'tableExample',\n table: {\n headerRows: 1,\n widths: [50, 30, 80, 80, 50, 240, 240],\n body: [\n Object.keys(msg.payload.query4[0]).map(key => { return { text: key, style: 'tableHeader' } }),\n ...msg.payload.query4.map(obj => Object.values(obj))\n ]\n },\n layout: 'lightHorizontalLines'\n },\n// Table 6\n { text: flow.get(\"m03\"), fontSize: 14, bold: true, margin: [12, 5, 12, 5] },\n {\n style: 'tableExample',\n table: {\n headerRows: 1,\n widths: [50, 30, 80, 80, 50, 240, 240],\n body: [\n Object.keys(msg.payload.query5[0]).map(key => { return { text: key, style: 'tableHeader' } }),\n ...msg.payload.query5.map(obj => Object.values(obj))\n ]\n },\n layout: 'lightHorizontalLines'\n },\n// Table 7\n { text: flow.get(\"m04\"), fontSize: 14, bold: true, margin: [12, 5, 12, 5] },\n \n {\n style: 'tableExample',\n table: {\n headerRows: 1,\n widths: [50, 30, 80, 80, 50, 240, 240],\n body: [\n Object.keys(msg.payload.query6[0]).map(key => { return { text: key, style: 'tableHeader' } }),\n ...msg.payload.query6.map(obj => Object.values(obj))\n ]\n },\n \n layout: 'lightHorizontalLines'\n },\n// Table 8\n { text: flow.get(\"m05\"), fontSize: 14, bold: true, margin: [12, 5, 12, 5] },\n \n {\n style: 'tableExample',\n table: {\n headerRows: 1,\n widths: [50, 30, 80, 80, 50, 240, 240],\n body: [\n Object.keys(msg.payload.query7[0]).map(key => { return { text: key, style: 'tableHeader' } }),\n ...msg.payload.query7.map(obj => Object.values(obj))\n ]\n },\n \n layout: 'lightHorizontalLines'\n },\n// Table 9\n { text: flow.get(\"m06\"), fontSize: 14, bold: true, margin: [12, 5, 12, 5] },\n \n {\n style: 'tableExample',\n table: {\n headerRows: 1,\n widths: [50, 30, 80, 80, 50, 240, 240],\n body: [\n Object.keys(msg.payload.query8[0]).map(key => { return { text: key, style: 'tableHeader' } }),\n ...msg.payload.query8.map(obj => Object.values(obj))\n ]\n },\n \n layout: 'lightHorizontalLines'\n },\n// Table 10\n { text: flow.get(\"m07\"), fontSize: 14, bold: true, margin: [12, 5, 12, 5] },\n \n {\n style: 'tableExample',\n table: {\n headerRows: 1,\n widths: [50, 30, 80, 80, 50, 240, 240],\n body: [\n Object.keys(msg.payload.query9[0]).map(key => { return { text: key, style: 'tableHeader' } }),\n ...msg.payload.query9.map(obj => Object.values(obj))\n ]\n },\n \n layout: 'lightHorizontalLines'\n },\n// Table 11\n { text: flow.get(\"m08\"), fontSize: 14, bold: true, margin: [12, 5, 12, 5] },\n \n {\n style: 'tableExample',\n table: {\n headerRows: 1,\n widths: [50, 30, 80, 80, 50, 240, 240],\n body: [\n Object.keys(msg.payload.query10[0]).map(key => { return { text: key, style: 'tableHeader' } }),\n ...msg.payload.query10.map(obj => Object.values(obj))\n ]\n },\n \n layout: 'lightHorizontalLines'\n },\n// Table 12\n { text: flow.get(\"m09\"), fontSize: 14, bold: true, margin: [12, 5, 12, 5] },\n \n {\n style: 'tableExample',\n table: {\n headerRows: 1,\n widths: [50, 30, 80, 80, 50, 240, 240],\n body: [\n Object.keys(msg.payload.query11[0]).map(key => { return { text: key, style: 'tableHeader' } }),\n ...msg.payload.query11.map(obj => Object.values(obj))\n ]\n },\n \n layout: 'lightHorizontalLines'\n },\n// Table 13\n { text: flow.get(\"m10\"), fontSize: 14, bold: true, margin: [12, 5, 12, 5] },\n \n {\n style: 'tableExample',\n table: {\n headerRows: 1,\n widths: [50, 30, 80, 80, 50, 240, 240],\n body: [\n Object.keys(msg.payload.query12[0]).map(key => { return { text: key, style: 'tableHeader' } }),\n ...msg.payload.query12.map(obj => Object.values(obj))\n ]\n },\n \n layout: 'lightHorizontalLines'\n },\n// Table 14\n { text: flow.get(\"m11\"), fontSize: 14, bold: true, margin: [12, 5, 12, 5] },\n \n {\n style: 'tableExample',\n table: {\n headerRows: 1,\n widths: [50, 30, 80, 80, 50, 240, 240],\n body: [\n Object.keys(msg.payload.query13[0]).map(key => { return { text: key, style: 'tableHeader' } }),\n ...msg.payload.query13.map(obj => Object.values(obj))\n ]\n },\n \n layout: 'lightHorizontalLines'\n },\n// Table 15\n { text: flow.get(\"m12\"), fontSize: 14, bold: true, margin: [12, 5, 12, 5] },\n \n {\n style: 'tableExample',\n table: {\n headerRows: 1,\n widths: [50, 30, 80, 80, 50, 240, 240],\n body: [\n Object.keys(msg.payload.query14[0]).map(key => { return { text: key, style: 'tableHeader' } }),\n ...msg.payload.query14.map(obj => Object.values(obj))\n ]\n },\n \n layout: 'lightHorizontalLines'\n },\n// Table 16\n { text: flow.get(\"m13\"), fontSize: 14, bold: true, margin: [12, 5, 12, 5] },\n \n {\n style: 'tableExample',\n table: {\n headerRows: 1,\n widths: [50, 30, 80, 80, 50, 240, 240],\n body: [\n Object.keys(msg.payload.query15[0]).map(key => { return { text: key, style: 'tableHeader' } }),\n ...msg.payload.query15.map(obj => Object.values(obj))\n ]\n },\n \n layout: 'lightHorizontalLines'\n },\n// Table 17\n { text: flow.get(\"m14\"), fontSize: 14, bold: true, margin: [12, 5, 12, 5] },\n \n {\n style: 'tableExample',\n table: {\n headerRows: 1,\n widths: [50, 30, 80, 80, 50, 240, 240],\n body: [\n Object.keys(msg.payload.query16[0]).map(key => { return { text: key, style: 'tableHeader' } }),\n ...msg.payload.query16.map(obj => Object.values(obj))\n ]\n },\n \n layout: 'lightHorizontalLines'\n },\n// Table 18\n { text: flow.get(\"m15\"), fontSize: 14, bold: true, margin: [12, 5, 12, 5] },\n \n {\n style: 'tableExample',\n table: {\n headerRows: 1,\n widths: [50, 30, 80, 80, 50, 240, 240],\n body: [\n Object.keys(msg.payload.query17[0]).map(key => { return { text: key, style: 'tableHeader' } }),\n ...msg.payload.query17.map(obj => Object.values(obj))\n ]\n },\n \n layout: 'lightHorizontalLines'\n },\n// Table 19\n { text: flow.get(\"m16\"), fontSize: 14, bold: true, margin: [12, 5, 12, 5] },\n \n {\n style: 'tableExample',\n table: {\n headerRows: 1,\n widths: [50, 30, 80, 80, 50, 240, 240],\n body: [\n Object.keys(msg.payload.query18[0]).map(key => { return { text: key, style: 'tableHeader' } }),\n ...msg.payload.query18.map(obj => Object.values(obj))\n ]\n },\n \n layout: 'lightHorizontalLines'\n },\n// Table 20\n { text: flow.get(\"m17\"), fontSize: 14, bold: true, margin: [12, 5, 12, 5] },\n \n {\n style: 'tableExample',\n table: {\n headerRows: 1,\n widths: [50, 30, 80, 80, 50, 240, 240],\n body: [\n Object.keys(msg.payload.query19[0]).map(key => { return { text: key, style: 'tableHeader' } }),\n ...msg.payload.query19.map(obj => Object.values(obj))\n ]\n },\n \n layout: 'lightHorizontalLines'\n }\n \n \n \n \n \n \n// \n ],\n \n styles: {\n header: {\n fontSize: 12,\n bold: true,\n margin: [12, 2, 12, 2]\n },\n subheader: {\n fontSize: 12,\n bold: true,\n margin: [12, 2, 12, 2]\n },\n tableExample: {\n fontSize: 10,\n bold: false,\n },\n tableExample1: {\n fontSize: 12,\n bold: false,\n },\n tableHeader: {\n bold: true,\n fontSize: 12,\n color: 'red'\n }\n },\n defaultStyle: {\n // alignment: 'justify'\n }\n\n};\n\nmsg.payload = tableData;\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1950,"y":2940,"wires":[["40d529f50ed4be79"]]}]

```

---

<div class="post-metadata">

**Author:** ![UnborN](https://avatars.discourse-cdn.com/v4/letter/u/4491bb/32.png) [@UnborN](https://discourse.nodered.org/u/UnborN)\
**Post date:** [29 September 2022 07:05 UTC](https://discourse.nodered.org/t/conditionally-right-align-selected-columns-in-pdfmake-both-column-headers-and-column-contents/68131/9 "2022-09-29T07:05:34Z")

</div>

i havent tested it but .. maybe you can check whether the `key` (header) startsWith a certain string and use either right or left alignment

```javascript
body: [
                            Object.keys(msg.payload.query0[0]).map(key => {
                                return {
                                    text: key,
                                    alignment : key.startsWith("Down Time Minutes") ? "right" : "left"
                                    //style: 'tableHeader'
                                }
                            }),
                            ...query0Data
                        ]

```

---

<div class="post-metadata">

**Author:** ![smanjunath211](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/smanjunath211/32/95742_2.png) [@smanjunath211](https://discourse.nodered.org/u/smanjunath211)\
**Post date:** [29 September 2022 15:55 UTC](https://discourse.nodered.org/t/conditionally-right-align-selected-columns-in-pdfmake-both-column-headers-and-column-contents/68131/10 "2022-09-29T15:55:22Z")

</div>

Thank You... Absolutely delighted to have achieved what I sought.

Before

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/d/2/d2d034efa4ee09b0a290ebf1d10ead39539f8c3a.png)

After

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/b/e/be986b5ba1634f6f558558b73e7be17bde21545a.png)

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [13 October 2022 15:55 UTC](https://discourse.nodered.org/t/conditionally-right-align-selected-columns-in-pdfmake-both-column-headers-and-column-contents/68131/11 "2022-10-13T15:55:24Z")

</div>

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
