Print title Changed based on JSON returned value

Print title Changed based on JSON returned value

bart1965bart1965 Posts: 2Questions: 0Answers: 0
edited April 2018 in Free community support

I have a datatable with the partial structure below. I have the table data coming back in a set called CutSheetData and I have a count coming back as Heats. using the dataSrc, I am populating a hidden field with the Heats value and I can see it after the ajax runs and the table shows correctly. I have the print title being created based on some selected values and I want to include the Heat count too. I can't find the right combination to have the heat value from the hidden table show up in the print preview. I just get a blank.

  $('#tblCutSheet').DataTable({
        "processing": true,
        "serverSide": true,
        destroy: true,
        "language": {
          processing: '<i class="fa fa-spinner fa-spin fa-3x fa-fw"></i><span class="sr-only">Loading...</span> '
        },

        "dom": "Brt",
        "buttons": [{
          extend: 'print',
          text: 'Print',
          title: $("#meltOrderList :selected").text() + ' Cut Sheet for ' + $('#txtheats').text() + ' heats of Grade ' + $("#meltOrderList :selected").val(),
          exportOptions: {
            stripHtml: false
          }
        }],
        "ajax": {
          "url": '@Url.Action("GetCutSheet", "Q3Met")',
          "type": "POST",
          data: {
            "selectedMeltOrder": $("#meltOrderList :selected").text(),
            "selectedGrade": $("#meltOrderList :selected").val(),
            "options": options
          },
          "dataSrc": function(json) {
            $('#txtheats').attr('text', json.Heats);
            return json.CutSheetData;
          }
        },

Replies

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

    Hi @bart1965 ,

    The problem is because when you initialise it like that, the title is constructed at initialisation time, i.e. before the Heats value has been retrieved.

    To make it use the current value, turn it into a function:

      title: function() {
        return  $("#meltOrderList :selected").text() + ' Cut Sheet for ' + $('#txtheats').text() + ' heats of Grade ' + $("#meltOrderList :selected").val();
      },
    

    Cheers,

    Colin

  • bart1965bart1965 Posts: 2Questions: 0Answers: 0

    Thanks! I had to change $('#txtheats').attr('text') in the title to get the text, but it works.

This discussion has been closed.