How to get the table ID for multiple tables when an export button is clicked?

How to get the table ID for multiple tables when an export button is clicked?

KevinRKevinR Posts: 3Questions: 1Answers: 0

Hello!

First of all, thank you for this great Plugin.
I can't figure out how to get the ID of the clicked table if I have multiple tables on my page. I would like to change the title for the export depending on the table where the export button has been clicked.
In principle I know that I can get the table ID for a single table using

let table = $('.table-data').DataTable();
let id = table.table().node().id;

But as soon as I have multiple tables I always only get the id of the first table. How do I get the ID of the clicked table?

Here is an example: https://jsfiddle.net/0xq5r7ke/3/
I would like to get the id "tableA" when the first "Copy Table Data" button is clicked and the id "tableB" when the second "Copy Table Data" button is clicked.

Thank you very much!

This question has an accepted answers - jump to answer

Answers

  • colincolin Posts: 15,143Questions: 1Answers: 2,586

    Where would you want to get the table ID? Is it to use it in the title function, or just elsewhere in the code?

    Colin

  • KevinRKevinR Posts: 3Questions: 1Answers: 0

    Yes, I would like to use it in the title function to set the title in dependence of the clicked table.

  • colincolin Posts: 15,143Questions: 1Answers: 2,586
    Answer ✓

    You can use the events to set a variable, which you can then use inside the title function - something like this.

    Colin

  • KevinRKevinR Posts: 3Questions: 1Answers: 0

    Thank you Colin, this worked out just perfectly!

This discussion has been closed.