Dynamically set print Message based on dropdown

Dynamically set print Message based on dropdown

yinswyinsw Posts: 3Questions: 1Answers: 0

I have a search panel with Dropdown selection and a Search button.

How do I dynamically set the button "Message" when I click the Print button? I've search all over the place but I can't find the solution. I just want to add some Report title based on what I filtered.

Kindly assist or let me know the information where I should refer to. Thanks.

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,356Questions: 1Answers: 10,447 Site admin

    You can't dynamically set the print message since there is no API to set it, but you can dynamically generate it by providing the message option as a function - e.g.:

    message: function () {
       return 'Hello world';
    }
    

    Its a regular Javascript function so you get information from the DOM, calculate values, whatever you need. Whatever you return from the function is what will be used.

    Allan

  • yinswyinsw Posts: 3Questions: 1Answers: 0

    The datatables already initialized upon accessing this page with the default search value. My search button will perform the following code when I click on it. I don't think I can set the message again when I click the Print button. What I want to do is the pass the variable $activity (my dropdown search filter value) to the Message variable.

            $('#btn-search').click(function() {
                $userID   = $('#inputUserID').val();
                $activity = $('#inputActivity').val();
                $dtFrom   = $('#inputStartDate').val();
                $dtTo     = $('#inputEndDate').val();
                
                dataTable.ajax.data = function(d) {
                    d.userID   = $userID;
                    d.activity = $activity;
                    d.dtFrom   = $dtFrom;
                    d.dtTo     = $dtTo;
                };
    
                dataTable.ajax.reload();
            });
    
  • allanallan Posts: 63,356Questions: 1Answers: 10,447 Site admin
    Answer ✓

    I don't think I can set the message again when I click the Print button.

    As I say, you can "set" the message, but you can dynamically create it.

    Just have the anonymous function for the message read the value from $('#inputActivity').val().

    Allan

  • yinswyinsw Posts: 3Questions: 1Answers: 0

    Ahh.. Now I get it.. Thank you sooooo much! Much appreaciated.

This discussion has been closed.