How to set a document's title (excelHtml5 and pdfHtml5) from a text field?

How to set a document's title (excelHtml5 and pdfHtml5) from a text field?

ricky2k7ricky2k7 Posts: 2Questions: 1Answers: 0

Hi, I need to change the title of an exported list (excelHtml5 and pdfHtml5) based on the value of an input field.
The idea is for the user to change the exported files title based on their searches.

For now all my buttons have the same title value:

{
    extend: 'excelHtml5',
    title: 'Title 1', //change this value based on an input field
},
{
    extend: 'pdfHtml5',
    title: 'Title 2', //change this value based on an input field
}

How can i accomplish this?

Answers

  • j.cuej.cue Posts: 7Questions: 1Answers: 0

    With jQuery you can grab the text input directly from your input field using a selector.
    This is what the HTML looks like:

     <input id="randomInputID" type='text'>
    

    Then do this for the title:

    title: $('#randomInputID').val()
    
  • ricky2k7ricky2k7 Posts: 2Questions: 1Answers: 0
    edited February 2017

    Hi j.cue, thanks for the reply.

    I've tried that but it doesn't work.
    The title variable is only loaded once with the datatable.

    I found a way to update the title property:

    action: function (e, dt, node, config)
    {
        ///update title property based on the added input field
        config.title = $("#exportTitle").val();
    
        ///procede with the export
        $.fn.dataTable.ext.buttons.pdfHtml5.action(e, dt, node, config);
    },
    
This discussion has been closed.