issue with Print with use from dropdown outside datatable

issue with Print with use from dropdown outside datatable

spiderkznspiderkzn Posts: 44Questions: 12Answers: 0
edited June 2023 in Free community support

Hi,

As I have print button in Datatable. So print working fine. But I need your help with using the text from dropdown **outside ** datatables that it require to display text in print. So in Datatable. I use the buttons:

{
         extend: "print",
         text: "Print <i class='fas fa-print'></i>",
         title: "Unit: " +
                 select_name(),
},

for Function:

function select_name() {
        return $("#ddName option:selected").text();
    }

So the problem is. when I change in dropdown and press print. the text does not change as it will use the previous text. not the one I have changed.

Can anyone help?

Edited by Allan - 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

Answers

  • allanallan Posts: 63,516Questions: 1Answers: 10,472 Site admin
    Answer ✓
    title: "Unit: " + select_name(),
    

    is executed when the button is added to the table. You want to delay the fetch of the data from select_ name() until when the user actually presses the button. For exactly that reason, title can be given as a function:

    title: function () {
      return 'Unit: ' + select_name();
    }
    

    Allan

  • spiderkznspiderkzn Posts: 44Questions: 12Answers: 0

    Thank you allan. it has solved my problem :)

Sign In or Register to comment.