Datatables button - table title attribute

Datatables button - table title attribute

jumpcutjumpcut Posts: 4Questions: 1Answers: 1

Anyone has a way to access the title attribute of a datatable from one of the export buttons which are set up in $.fn.dataTable.defaults?

I have multiple tables so the page <title> (i get this with $(document).find("title").text() ) does not apply to all.

In the export buttons $(this) only has button object but I would like to access the table so I cold access containing table's title. I tried .parent() .closest('table'). No dice.

I hoped something like $(this).parent().closest('table').attr('title') would work but it does not.

Thanks!

This question has an accepted answers - jump to answer

Answers

  • colincolin Posts: 15,240Questions: 1Answers: 2,599

    Hi @jumpcut ,

    We're happy to take a look, but it would help, as per the forum rules, if you could link to a running test case showing the issue so we can offer some help. Information on how to create a test case (if you aren't able to link to the page you are working on) is available here.

    Cheers,

    Colin

  • jumpcutjumpcut Posts: 4Questions: 1Answers: 1

    Hi @colin,
    Thanks for your response.

    Here is the example of including the table title attribute in excel file:
    http://live.datatables.net/cuhegebe/1

    When exporting the small table the values come from the top table, which makes sense because that is the first $('.dataTable').attr("title")

    One of my initial idea was to get the table id then pull the title as:$('#DataTables_Table_0').attr("title"), $('#DataTables_Table_1').attr("title") and so on... $('#DataTables_Table_' + tableID).attr("title")

    So the question is how to refer to the containing table from the export button or how to get tableID for the button object?

  • allanallan Posts: 63,542Questions: 1Answers: 10,476 Site admin
    Answer ✓

    The DataTable is actually passed in as the third parameter to the customize function - e.g.:

    customize: function (xlsx, win, dt) {
    

    You could then use $(dt.button(0).node()).attr('title') to get the title attribute (although its going to be the same in the example since it isn't customised per table).

    Allan

  • jumpcutjumpcut Posts: 4Questions: 1Answers: 1

    Thanks @allan
    It worked with $(dt.table(0).node()).attr('title')
    I updated the JS in case someone else would find it helpful to use table title attribute in file exports.

    http://live.datatables.net/fimevika/1/edit?html,js,output

This discussion has been closed.