set pdf export message from json

set pdf export message from json

crush123crush123 Posts: 417Questions: 126Answers: 18

on my pdfexport, i am pulling together a list of data specific to an event.

rather than show the event name multiple times in the list, i would like to hide the column and either append the event name to the title of the pdf, or the message.

I have extracted the data I need and set it as a variable using initComplete, and am using this data to update the table caption in the dom

initComplete: function ( settings, json ) {
          //mycaption = console.log(json.data[0].tblorderdetails.DetailName);
          mycaption = json.data[0].tblorderdetails.DetailName;
        $("caption").html(mycaption);
        },

How can i use the value in the pdf export button to set the message, if I try the following it is undefined ?

{
            extend: 'pdf',
            message: ''+mycaption+'',
            text: '<i class="fa fa-file-pdf-o" aria-hidden="true"></i> PDF',
            pageSize: 'A4',
            download: 'open',
            orientation: 'landscape',
            exportOptions: {
                columns: [1,2,4,5,6,7,8]
            }
}

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,678Questions: 1Answers: 10,497 Site admin
    Answer ✓

    Hi,

    Currently there isn't a method for doing this but Tom is looking into it and will get back to you.

    Allan

  • crush123crush123 Posts: 417Questions: 126Answers: 18

    cool, thanks

  • Tom (DataTables)Tom (DataTables) Posts: 139Questions: 0Answers: 26
    edited June 2016

    Hi

    I've updated the message option for both flash and html5 versions of the PDF buttons. It should now allow a function to be passed in as well as a static string.

    You can download the nightly build of buttons that will have the updated code in it from here- https://datatables.net/download/nightly#Buttons

    This will allow you to pass in your json, for example-

    message: function ( dt ) {
      return dt.ajax.json().data[0].tblorderdetails.DetailName;
    }
    

    Hope this help, if you have any more questions let me know

    Thanks

    Tom

  • crush123crush123 Posts: 417Questions: 126Answers: 18
    edited June 2016

    Downloaded the nightly build and updated the message, but get the following error...

    pdfmake.js:16062 Uncaught TypeError: Cannot read property 'text' of undefined

    if i replace the return value with a string., i also get the error

    i also tried adding a button action, which works, so I guess my syntax is ok

    action: function ( e, dt ) {
                    console.log(dt.row().data().tblorderdetails.DetailName);
                },
    
  • Tom (DataTables)Tom (DataTables) Posts: 139Questions: 0Answers: 26

    Could you post your button code that is giving you the error?

  • crush123crush123 Posts: 417Questions: 126Answers: 18

    vanilla page here

    http://test3.forthwebsolutions.com/vanilla_ticketsales.php?EventID=126

    (the nightly build js is uploaded, but resides in the 1.2.1 folder)

  • Tom (DataTables)Tom (DataTables) Posts: 139Questions: 0Answers: 26
    edited June 2016

    Apologies think I might of linked you to the wrong place as it seems buttons.html5.js you are using on that page is an older version without the updated code for the message option

    Try using this nightly file as it should include the updated code.

    https://nightly.datatables.net/buttons/js/buttons.html5.js

    Thanks

    Tom

  • crush123crush123 Posts: 417Questions: 126Answers: 18

    Sorted !

    Thanks

This discussion has been closed.