How to send custom data to DataTable server-side processing not from DataTable's filter input?

pheromix

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 :

enter image description here

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 ?

markpsmith

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.

editar em
0

deixe-me dizer algumas palavras

0comentários
loginDepois de participar da revisão

Artigos relacionados

How to get image src value from server side jquery datatable in datatable?

I need to send date data from server and then filter elements using date in google.visualization.datatable used in Google Charts

How can I adjust the columns after initializing server-side processing datatable?

Filter data within `datagridview` bounded from `datatable`

Formatting server side jQuery Datatable

In primeng Datatable custom filter not working

how to update empty datatable by the data from another datatable

How to edit a cell and delete a row from dataTable at serverside processing jquery

How to pull data out from datatable

how to insert data into datatable from variable

How to show data from get request in datatable?

PrimeNG DataTable server-side paging

Trigger DataTable highlight and filter base on input change

Exporte CSV / PDF obedecendo a condição de filtragem externa ao usar o Datatable Ajax Server Side Processing

Is it possible to filter a jQuery DataTable by data attribute?

How to get a single row data from a jquery datatable?

How to use clipboard to copy data from Excel Sheet to DataTable?

How to filter Laravel Datatable between two dates?

How to datatable.Select() filter numeric

Is there a way to get aocolumns from the server in datatable editable?

How to send data from server to Android?

Getting data from datatable then passing it to php with ajax

import data from excel 2003 to dataTable

get repeated data from datatable c#

Custom filtering With Button for Datatable

datatable jquery how to see data of the table in console

How to create a datatable with arbitrary columns and data?

How to create an object from a Datarow of Datatable in Flutter

How to transmit data to client-side js file from the server?