In my page there is a group of four fields to make custom search
of records in the database ; the results will be displayed inside a DataTable
which is displayed below these group of fields :
Here is the javascript creation of the DataTable :
<script type="text/javascript">
$(document).ready(function() {
var j_table = $("#t_list").dataTable( {
"oLanguage" : {
"sInfoThousands": " ",
"sEmptyTable" : _getText("datatable_resultat_zero", "global"),
"sInfo" : _getText("datatable_zone_statut_info", "global"),
"sInfoEmpty" : "",
"sInfoFiltered" : _getText("datatable_zone_statut_filtre", "global"),
"sLengthMenu" : _getText("datatable_zone_nb_affichage", "global"),
"sSearch" : _getText("datatable_zone_filtre", "global"),
"sZeroRecords" : _getText("datatable_resultat_zero", "global"),
"oPaginate" : {
"sPrevious" : _getText("datatable_btn_prcdt", "global"),
"sNext" : _getText("datatable_btn_svt", "global")
}
},
"sPaginationType" : "bootstrap",
"aoColumnDefs": [
{ "aTargets": [ 3 ], "bSortable": false },
{ "aTargets": [ 3 ], "bSearchable": false },
{
"aTargets": [ 3 ],
"mRender": function ( data, type, full ) {
return '<div style="text-align: center;"><a href="<?php echo site_url('meeting/modif'); ?>/'+data+'" title="Modifier"><button class="btn btn-mini">Detail</button></a></div>';
}
}
],
"bServerSide": true,
"sAjaxSource": "<?php echo site_url('ajax/dataTableListerMeetingNotes'); ?>",
"sServerMethod": "POST"
} );
});
</script>
So how to pass the values entered in the four fields to the ajax source of the DataTable
when clicking the "Valider" blue button ? And how to collect these data inside the script
called by the DataTable's ajax
?
Use fnServerParams.
Add this to your initialisation code, and every time you call fnDraw()
, the parameters will be passed in the datatable request. Obviously you'll have to change the jquery selectors to match your input Ids.
"sServerMethod": "POST",
"fnServerParams": function (aoData) {
aoData.push({ "name": "sujet", "value": $('#Sujet').val() });
aoData.push({ "name": "lieu", "value": $('#Lieu').val() });
aoData.push({ "name": "dateDu", "value": $('#DateDu').val() });
aoData.push({ "name": "dateAu", "value": $('#DateAu').val() });
},
In the Valider
button click event you call j_table.fnDraw()
On the server side, you access the parameters in the same way as the standard datatables parameters, ie get the from the querystring:
$_POST['sujet']
I'm not familiar with PHP but It'll be something like that.
Este artigo é coletado da Internet.
Se houver alguma infração, entre em [email protected] Delete.
deixe-me dizer algumas palavras