numbers not showing for PDF

numbers not showing for PDF

wathertonwatherton Posts: 33Questions: 6Answers: 0
edited August 2015 in Buttons

I have a slight oddity, exporting a table using CSV, exports everything, however, using the pdf(html5) option my amount column is empty.

buttons: [
{
extend: 'colvis',
text: 'Show/Hide'
},

    {
        extend: 'csvHtml5',
        text: '<u>C</u>sv',
        key: {
            key: 'c',
            altKey: false
        },
        title: 'MI - Summary',
        fieldSeparator: '\t',
        extension: '.txt',
        download: 'open',
        exportOptions: {
            modifier: {
                page: 'current'
            },
            columns: [0, 1, 2, 3, 4, 5, 6, 7, 8, 10]
        }
    },
    {
        extend: 'pdfHtml5',
        orientation: 'landscape',
        pageSize: 'LEGAL',
        text: '<u>E</u>xport Page (PDF)',
        key: {
            key: 'e',
            altKey: false
        },

        customize: function (doc) {
            doc.content.splice(0, 1, {
                margin: [0, 0, 0, 24],
                fit: [100, 100],
                image: "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAASwAAABbCAIAAABGTy/vAAAAGXRFWHRTb2Z0d2FyZQBBZG9"
            });
            doc.content.splice(1, 0, {
                margin: [0, 0, 0, 12],
                alignment: 'left',
                text: 'MI - Summary',
                fontSize: 15
            });
        },
        download: 'open',
        exportOptions: {
            modifier: {
                page: 'current'
            },
            columns: [0,1,2,3,4,5,6,7,8,10]
        }
    }
   ],

Why is this?

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,516Questions: 1Answers: 10,472 Site admin

    Can you link to the page so I can debug it please?

    Allan

  • wathertonwatherton Posts: 33Questions: 6Answers: 0

    Morning Alan,

    Link the page?

    Sorry not sure what you mean.

  • wathertonwatherton Posts: 33Questions: 6Answers: 0
    edited August 2015

    http://debug.datatables.net/ekibex

    think this is what you mean.

    Found the Debugger page.

  • allanallan Posts: 63,516Questions: 1Answers: 10,472 Site admin

    Can you give me a URL to a page which shows the issue so I can debug it. Unfortunately the debugger doesn't show why this is going wrong.

    Allan

  • wathertonwatherton Posts: 33Questions: 6Answers: 0

    Alas, there we have a problem, as this is an internal site, not publicly available. Happy to send you a webex session though.

  • tubedisasterstubedisasters Posts: 7Questions: 1Answers: 1
    edited September 2015 Answer ✓

    I had the same problem and found that any columns that contained non-String values were not displayed. I had a requirement to cast certain column values to ints or floats (e.g. via 'parseInt()') because I needed to add them together to display in a 'total' column. Make sure that all of your table values are cast to String (e.g. amount.toString()) when they are displayed and hopefully your problem will go away.

  • wathertonwatherton Posts: 33Questions: 6Answers: 0

    Thanks tubedisasters (not sure on the tag name BTW), I shall try that, but one thing that surprises me in your response, is that all the data is JSON, so should be treated as text/string. i'll report back if this fixes the issue for myself also.

  • wathertonwatherton Posts: 33Questions: 6Answers: 0

    Bingo, had to use the render method in the ColDefs function:

    {
    "render": function ( data, type, row ) {
    return data.toString()
    },
    "targets": 5
    },

    Which now populates the missing Amount value in the PDF.

    Thanks.

  • tubedisasterstubedisasters Posts: 7Questions: 1Answers: 1

    On the tag name. I should stop using it. Its the name of a song by the punk band Flux Of Pink Indians from 1981 and unrelated to the terrible disaster that occurred over 20 years later. Being an Australian I never considered it might be inappropriate but can see that people could easily get offended.

  • jLinuxjLinux Posts: 981Questions: 73Answers: 75

    Wait, what disaster occurred 20+ years later? lol

  • allanallan Posts: 63,516Questions: 1Answers: 10,472 Site admin

    The London terrorist atrocities of 2005 I suspect. I hadn't made the connection initially myself I must confess.

  • hheimbuergerhheimbuerger Posts: 14Questions: 1Answers: 0

    I just ran into the exact same problem. I found it rather odd and unintuitive that the export of 'num' type columns would work for CSV and Print, but not for PDF and Copy.

    Allan, any chance to have the buttons extension in the future automatically do this conversion to a string when possible?

    Alternatively, could a note on this be added to the PDF button manual page?

  • allanallan Posts: 63,516Questions: 1Answers: 10,472 Site admin

    Hi,

    Thanks for posting. Can you link to a page showing the issue please? I asked a couple of times above, but haven't had a reproducible test case for this yet, so a link would be a huge help to being able to resolve this issue.

    Allan

  • hheimbuergerhheimbuerger Posts: 14Questions: 1Answers: 0
    edited October 2015

    Hi Allan,

    Yeah, sure! https://jsfiddle.net/osebsuf3/2/

    Here the Age doesn't render into the PDF until it's converted to a string (e.g. with a render method). The CSV export doesn't appear to work at all, this is not something I have experienced in development, but might be interesting to investigate as well.

    In my own codebase, I have another issue where a null value in a textual column will cause a pretty deep crash with the following stacktrace, but I haven't been successful in extracting that to a fiddle yet:

    Uncaught TypeError: Cannot read property 'length' of null
    normalizeTextArray @ datatables.js:25222
    measure @ datatables.js:25284
    TextTools.buildInlines @ datatables.js:25109
    DocMeasure.measureLeaf @ datatables.js:23725
    (anonymous function) @ datatables.js:23605
    StyleContextStack.auto @ datatables.js:25474
    DocMeasure.measureNode @ datatables.js:23590
    DocMeasure.measureTable.layout @ datatables.js:23877
    StyleContextStack.auto @ datatables.js:25474
    DocMeasure.measureTable @ datatables.js:23846
    (anonymous function) @ datatables.js:23603
    StyleContextStack.auto @ datatables.js:25474
    DocMeasure.measureNode @ datatables.js:23590
    DocMeasure.measureVerticalContainer @ datatables.js:23741
    (anonymous function) @ datatables.js:23597
    StyleContextStack.auto @ datatables.js:25474
    DocMeasure.measureNode @ datatables.js:23590
    DocMeasure.measureDocument @ datatables.js:23577
    LayoutBuilder.tryLayoutDocument @ datatables.js:11593
    LayoutBuilder.layoutDocument @ datatables.js:11581
    PdfPrinter.createPdfKitDocument @ datatables.js:9453
    Document._createDoc @ datatables.js:9249
    Document.getBuffer @ datatables.js:9335
    DataTable.ext.buttons.pdfHtml5.action @ datatables.js:93104
    (anonymous function) @ datatables.js:91425
    jQuery.event.dispatch @ jquery-1.11.1.js:4641
    jQuery.event.add.elemData.handle @ jquery-1.11.1.js:4309
    

    (line numbers from https://cdn.datatables.net/r/bs/jszip-2.5.0,pdfmake-0.1.18,dt-1.10.9,b-1.0.3,b-html5-1.0.3,b-print-1.0.3/datatables.js )

  • hheimbuergerhheimbuerger Posts: 14Questions: 1Answers: 0
  • hheimbuergerhheimbuerger Posts: 14Questions: 1Answers: 0

    The aforemented problem with the CSV export seems to be caused by numerical values in the dataset (as shown in the fiddle).

    I still haven't had any luck reproducing the crash in the PDF export when there's a null value in the dataset, even though I can reliably reproduce that in my development project across all columns.

  • allanallan Posts: 63,516Questions: 1Answers: 10,472 Site admin

    Awesome - thanks for the test case.

    I've just committed the required fix for the PDF export. The CSV export already worked with the nightly version and the null issue you mentioned can be resolved by setting the columns.defaultContent for the column since that is required to tell DataTables what to do with null data.

    I've updated the fiddle with the nightly version and columns.defaultContent now and it appears to work as required: https://jsfiddle.net/osebsuf3/3/ .

    The fixes will be included in the next Buttons release which I expect to be within 2 weeks time.

    Regards,
    Allan

  • hheimbuergerhheimbuerger Posts: 14Questions: 1Answers: 0

    Amazing, thanks Allan!

  • hheimbuergerhheimbuerger Posts: 14Questions: 1Answers: 0

    Allan, I think there's one more case: the excelHtml5 option with numerical cells breaks with something like Uncaught TypeError: a[c].match is not a function (it tries to run a regex on the int value).
    Again, just turning the cell into a string fixes the problem, but of course expected behavior would be for the excel export to render ints out-of-the-box.

    Fiddle updated: https://jsfiddle.net/osebsuf3/5/

  • allanallan Posts: 63,516Questions: 1Answers: 10,472 Site admin

    Thank you - fixed in the updated nightly: https://jsfiddle.net/osebsuf3/6/ .

    Allan

  • hheimbuergerhheimbuerger Posts: 14Questions: 1Answers: 0

    Great, thanks!

  • hheimbuergerhheimbuerger Posts: 14Questions: 1Answers: 0

    Is there a timeline for releasing the Buttons extension 1.0.4? I would like to get my production system off the (locally hosted) nightly builds and onto a proper release.

    Thanks for the fixes, all of these now work very well for us!

  • allanallan Posts: 63,516Questions: 1Answers: 10,472 Site admin
    edited October 2015

    I expect it to be next week now. It will also likely be v1.1.0.

    Allan

This discussion has been closed.