jsessionid lost/reset when using Datatables “buttons: extend: print” in Firefox

jsessionid lost/reset when using Datatables “buttons: extend: print” in Firefox

edwardiv1edwardiv1 Posts: 11Questions: 2Answers: 0
edited July 2019 in Free community support

I'm using the Datatables "buttons: extend: print" to print a table.

When I press the Print button, it opens a new browser tab with the table and Firefox's print dialog is display, which is what I expect, but it also resets the JSESSIONID, meaning the user is effectively logged out. The user is forced to login again when they try hit refresh or navigate to another page.

If I try a PDF export (via extend: 'pdf'), it works fine. The problem only occurs for printing and only in Firefox. The session is not lost in either Safari or Chrome. I'm using Firefox 68.0, but this was also happening in 67 (I haven't tested earlier versions).

It makes no difference if stateSave is true, false or omitted.

<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/v/bs/dt-1.10.18/datatables.min.css"/>
<script type="text/javascript" src="https://cdn.datatables.net/v/bs/dt-1.10.18/datatables.min.js"></script>
<script type="text/javascript" src="https://cdn.datatables.net/buttons/1.5.6/js/dataTables.buttons.min.js"></script>
<script type="text/javascript" src="https://cdn.datatables.net/buttons/1.5.6/js/buttons.print.min.js"></script>

function init() {
  $.fn.dataTable.moment( 'DD/MM/YYYY' );
  $.fn.dataTable.moment( 'MM/DD/YYYY' );
  $.fn.dataTable.moment( 'MMM D, YYYY' );

  dtApi = $('.mydatatableclass').DataTable( {
  "pageLength": 50,
  "lengthChange": false,
  "order": [[ 1, "asc" ]],
  stateSave: true,
  "columnDefs": [
    { "visible": false, "targets": 10 },
    { "orderable": false, "targets": [0,3,8,9] }
  ],
  buttons: [
    {
      extend: 'print',
      exportOptions: {
        columns: [1,2,4,5,6,7,10]
      }
    }
  ]
} );
<a href="#" onclick="$('.mydatatableclass').DataTable().button( '.buttons-print' ).trigger();">Print Table</a>

Answers

  • edwardiv1edwardiv1 Posts: 11Questions: 2Answers: 0
    edited July 2019

    Additional info: JSESSIONID is a browser cookie set by a Java server. It's used to track a user's session on a website and is how the server knows whether a user is logged in or not, so if the cookie disappears, the server thinks the user is no longer logged in.

    So printing with Datatables seems to be destroying the cookie.

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

    Hi @edwardiv1 ,

    That wouldn't be a DataTables issue, it has no knowledge of JSESSIONIDS. And as it's working as expected on some browsers it suggests something to do with FF. Maybe some other users have experience on this (or your SO thread is responded to).

    Cheers,

    Colin

This discussion has been closed.