How to right align numeric columns in exported pdf and excel?

How to right align numeric columns in exported pdf and excel?

osamajavedosamajaved Posts: 12Questions: 6Answers: 0

How to right align numeric columns in exported pdf and excel?

This question has accepted answers - jump to:

Answers

  • allanallan Posts: 61,726Questions: 1Answers: 10,109 Site admin
    Answer ✓

    With the Excel export it should be done automatically. With the PDF export you would need to use the customize method of the pdfHtml5 button type, together with the pdfmake API to right align whatever cells it is that you need.

    I'll look at adding that by default in future.

    Allan

  • osamajavedosamajaved Posts: 12Questions: 6Answers: 0
    edited September 2018

    Thank you Allan, It worked for me as follow:

    customize: function (doc) {
                        var iColumns = $('#ProjectReport thead th').length;
    
                        var rowCount = document.getElementById("ProjectReport").rows.length;
                        var groupByValue = $('#GroupByFilter option:selected').data('index');
    
                        for (i = 0; i < rowCount; i++) {
                           
                                doc.content[1].table.body[i][iColumns - 1].alignment = 'right';
                                doc.content[1].table.body[i][iColumns - 2].alignment = 'right';
                                doc.content[1].table.body[i][iColumns - 3].alignment = 'right';
                            
                        };
                    }
    
  • moriamoria Posts: 10Questions: 4Answers: 1
    edited February 2019 Answer ✓

    Your solution worked for me @osamajaved . I only wanted certain columns to be re-aligned, not all.

    EDIT: I only used:
    var rowCount = doc.content[1].table.body.length;
    for (i = 1; i < rowCount; i++) {
    doc.content[1].table.body[i][4].alignment = 'right';
    doc.content[1].table.body[i][5].alignment = 'right';
    doc.content[1].table.body[i][6].alignment = 'right';
    }
    ;},

This discussion has been closed.