我使用的数据表与服务器端的处理。 我能额外的参数发送给服务器,但只有当表被装载在第一次或当表被重新加载由于过滤,排序等,我想多余的参数被发送到服务器,他们被送到我每次从选择字段的值。 我怎样才能实现这一行为? 提前致谢。
这是我的数据表脚本
<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>
我也试过用这段代码:
"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)
} );
而我的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>