write "titleAttr" to variable

write "titleAttr" to variable

abickfordabickford Posts: 10Questions: 4Answers: 0
edited October 2021 in DataTables

I have created a custom button that runs a function to create a word document. One of the inputs to the dataTable is a "titleAttr" value (which specifies the type of table). I want to write the titleAttr value to a variable that I will pass to a function that will create a table. The code:

The function that manages the custom button:

//Data Table WordButton creator
$.fn.dataTable.ext.buttons.word = {
    className: 'buttons-word',
   action: function ( e, dt, node, config ) {
                var colhead = dt.columns().header().toArray().map(x => x.innerText); //The table headers
            var colfooter = dt.footer().toArray().map(x => x.innerText);  //The table footer
            var table = dt.rows().data();  // The table itself
                     var tableTitle = ???
                    genWordTbl(colhead, colfooter, table, tableTitle); //The code to create and download a word document
        } //action function....

The creation of the custom button:

    $('#summtab').DataTable( {
                dom: 'Bfrtip',
        buttons: [
         extend: 'word',
         titleAttr: fileName, <- this is the value I want to write to genWordTbl 
         text: "Word",
         footer : true
     {Other buttons...}

How do I recover the value of titleAttr and write it to the genWordTbl function?
I have to note that with the other buttons (csv, excel, and PDF) this functionality exists.

Edited by Colin - Syntax highlighting. Details on how to highlight code using markdown can be found in this guide.

This question has an accepted answers - jump to answer


  • allanallan Posts: 55,064Questions: 1Answers: 8,644 Site admin
    Answer ✓

    In your action function, config.titleAttr will give you the value of whatever titleAttr is been set to (in this case whatever fileName is.


Sign In or Register to comment.