filename: need table id

filename: need table id

kdpowellkdpowell Posts: 10Questions: 3Answers: 0
edited June 2018 in Buttons

QUESTION: How could I grab the (this) table id when the PDF button is clicked?
(Everything else is working, except this filename.)

{
                extend: "pdf",
                text: "Save PDF",
                filename: function(){
                    var d = new Date();
                    var n = d.getTime();


                    var tableID = "**_need table ID here_**";
                    return tableID + "_" + n;**


                },
                exportOptions: {
                    stripNewlines: false,
                    columns: [0,1,2,3]
                }
}

This question has an accepted answers - jump to answer

Answers

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

    Hi @kdpowell ,

    You can use the settings() - as in the example here.

    Cheers,

    Colin

  • kdpowellkdpowell Posts: 10Questions: 3Answers: 0
    edited June 2018

    Hi @colin,
    I tried it out... but I'm using a class and not an id (see below) because I have two tables on the screen. When I implemented the settings as depicted in the fiddle, it worked! It correctly used the id of the first table when I clicked the pdf button, HOWEVER when I clicked the button with the 2nd table, it was still using the id of the table of the first button for the filename :'( .

    The big question:
    How could I do this if I am using a class (more than one table on screen) ?

    var table = $('.tblData').DataTable (
    

    as opposed to (using table id)...

    var table = $('#tblData').DataTable (
    
  • colincolin Posts: 15,237Questions: 1Answers: 2,599

    Hi @kdpowell ,

    Probably the best thing would be if you could tweak that fiddle so it looks like what you've got, that way we'll be looking/thinking about the same thing. Or if it's easier, link to your page instead,

    Cheers,

    Colin

  • kdpowellkdpowell Posts: 10Questions: 3Answers: 0

    @colin

    Thank you for your attention to this so far :smile:

    Here's a fiddle I've been fiddling with: my fiddle looking for solution

  • colincolin Posts: 15,237Questions: 1Answers: 2,599
    Answer ✓

    Hi @kdpowell ,

    You're welcome, and here's a tidy fix for you. There's no way of doing it in the filename function, as there's nothing passed into it, so each table needs to be declared individually. However, this can be done tidily without code duplication as in this example here.

    Hope that works for you,

    Cheers,

    Colin

This discussion has been closed.