I'm using Datatables with server-side processing. I'm able to send extra 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 the extra parameters to be sent to the server every time I select a value from the select field. How can I achieve this behavior?. Thanks in advance.
This is my datatables script
<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 with this piece of code:
"fnServerData": function ( sSource, aoData, fnCallback ) {
/* Add some extra data to the sender */
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>