jquery datatable : How to save a variable on server side?

jquery datatable : How to save a variable on server side?

matt.crawfoordmatt.crawfoord Posts: 31Questions: 13Answers: 0
edited July 2016 in Free community support

I have a server side processing jquery datatable ,i have to save a variable (scroll_id) when server side callback to client , the scroll_id have to used on server side , then server side will be produce a new scroll_id , the scroll_id is like "start" in server side query ,
the variable can determines first record index on server side

<script type="text/javascript" charset="utf8" src="//code.jquery.com/jquery-1.12.3.js"></script>
<script type="text/javascript" charset="utf8" src="https://cdn.datatables.net/1.10.12/js/jquery.dataTables.min.js"></script>
<script>
$(document).ready(function() {   
 $.fn.dataTable.ext.errMode = 'none';
   var table = $('#example').DataTable( {
    "processing": true,
    "serverSide": true,
    "jQueryUI": true,
     "ordering": true,
     "searching": true,
     "order": [[1, 'desc']],//set column 1 (time)
      "ajax": {
       url: "process.php",
       type: 'POST',
       data: {
       start: "<?php echo $start; ?>",
       end: "<?php echo $end; ?>"
          }
       },    
    "columns": [
        {
            "className":'details-control',
            "orderable":false,
            "data":null,
            "defaultContent": ''
        },
        { "data": "time"},
         { "data": "message"}

    ],
     "dom": "rtiS",
     "scrollY": 400,
    "scroller": {
         "loadingIndicator": true
    },
    "deferRender":    true

} );

// Add event listener for opening and closing details
$('#example tbody').on('click', 'td.details-control', function () {
    var tr = $(this).closest('tr');
    var row = table.row( tr );       
    if ( row.child.isShown() ) {
        // This row is already open - close it
        row.child.hide();
        tr.removeClass('shown');
    }
    else {
        // Open this row
        row.child( format( row.data())).show();
        tr.addClass('shown');
     }
  } );
} );
</script>
 <body>
   <table id="example" class="display" cellspacing="0" width="100%">
   <thead>
       <tr>
          <th ></th>
           <th data-search-index="3">time</th>
           <th data-search-index="3">Message</th>
           </tr>
    </thead>
              <tfoot>
                <tr>
                  <th></th>
                  <th>time</th>
                  <th>Message</th>
                </tr>
              </tfoot>
            </table>
</body>

process.php

 $search='';
 $requestData= $_REQUEST;
 if(isset($_POST["search"]["value"]) && !empty($_POST["search"]["value"])){
 $search ='&q=_all:'.$_POST["search"]["value"];
 }
$qryurl ='<ip>/log/_search?scroll=30s'.$scroll_id;

.......
    $scroll_id = [new_scroll_id];  // each request will be get a new scroll_id
 .......
 //json output 
 $results = array(
   "draw"  => intval($requestData['draw']),
    "iTotalRecords" =>intval($total),
      "iTotalDisplayRecords" => intval($total),
     "aaData"=>$sourceary
    );

the variable is like "start" in server side query ,
the variable can determines first record index on server side ,
How can I save the variable in order to used on server side when "start" have changed ?
any suggestion? Thank a lot, More

This discussion has been closed.