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

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).

//  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

the below code snippet works for static data

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

image

from your code i see that you have already applied a style called tableExample to the table
so based on the pdfmake documenation 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

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;

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

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

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.

thanks.

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.

{
                        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',
         },

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
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;
1 Like

Perfect!. You are a genius! :+1:

image

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.

1 Like

Done. successfully adapted to my table.

How do we do the same for column headers ?

my function node

[{"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"]]}]

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

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

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

Before

After

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