I am using Datatables with server side processing. I can send additional parameters to the server, but they are sent only when the table is loaded for the first time or when the table is reloaded due to filtering, ordering, etc. I want additional parameters sent to the server every time I select a value from the select box. How can I achieve this behavior? Thanks in advance.
This is my datatables script data
<script> $(document).ready(function() { $('#tabla').dataTable( { "sDom": '<"top"l>rt<"bottom"pi><"clear">', "processing": true, "serverSide": true, "sPaginationType": "full_numbers", "bProcessing": true, "sAjaxSource": "server_side3.php?action=table_data", "bDeferRender": true, "aLengthMenu": [10, 25, 40], "contentType": "application/json; charset=utf-8", "dataType": "json", "fnServerParams": function ( aoData ) { aoData.push( { "name": "year", "value": $( "#year option:selected" ).text() } ); }, language: { url: '//cdn.datatables.net/plug-ins/380cb78f450/i18n/Spanish.json' } } ).columnFilter(); } ); </script>
I also tried using this piece of code:
"fnServerData": function ( sSource, aoData, fnCallback ) { aoData.push( { "name": "year", "value": $( "#year option:selected" ).text() } ); $.getJSON( sSource, aoData, function (json) { fnCallback(json) } );
And my html
<select id="year"> <?php echo '<option value="'.date(Y).' selected">'.date(Y).'</option>'; for ($i=2005; $i < date(Y) ; $i++) { echo '<option value="'.$i.'">'.$i.'</option>'; } ?> </select>
jquery server-side datatables
sms
source share