How can i save the value of search field?

How can i save the value of search field?

Jordano95Jordano95 Posts: 3Questions: 2Answers: 0
edited May 2018 in Free community support

hello!

I would like to send with POST the value of the field "search" of datatable to use it to initialize another page , it is possible ?
i try in thi way

$(document).ready(function() {
     var table = $('#elencoprodotti').DataTable( {
        
        "language": {
            "url": "//cdn.datatables.net/plug-ins/9dcbecd42ad/i18n/Italian.json",
            "decimal": ",",
            "thousands": "."
        },
        "ajax": {
            "url": modulo+"_get_elenco.php?tabella=", 
            "dataSrc": ""
        },
        "columns": [
            { "data": "IMG" },
            { "data": "CODICE" },
            { "data": "CODICE_OBSOLETO" },
            { "data": "DESCRIZIONE" },
            { "data": "CATEGORIA" },
            { "data": "FORNITORE" },
            { "data": "UM_BREVE" },
            { "data": "QTA_NEW" },
            { "data": "SCORTA_MINIMA" }
        ],
        "columnDefs": [
            {  
                
                "targets": [0],
                "searchable": false, // disabilita la ricereca per il campo con indice 0
                "orderable": false // disabilita l'ordinamento4
                
            },
 $('#elencoprodotti').on('change', function() {
    var value = $('.dataTables_filter input').val();
    //alert(value); // <-- the value
      $.ajax({
        type:"POST",
        method:"POST",
        url: "ciao.php",
        data:{ 'value': value},
        success: function(){
            alert(value);
        
    }

    });

This question has an accepted answers - jump to answer

Answers

  • colincolin Posts: 15,237Questions: 1Answers: 2,598

    Hi @Jordano95,

    That's close - take a look at this page here. For you, this should do the trick:

    "data": function ( d ) {
      d.mySearch = value;
    }
    

    Cheers,

    Colin

  • Jordano95Jordano95 Posts: 3Questions: 2Answers: 0

    thanks @colin for the answer but how can i include it in my code?
    sorry but i'm new with javascript and ajax

  • colincolin Posts: 15,237Questions: 1Answers: 2,598
    Answer ✓

    You currently have

    data:{ 'value': value},
    

    so just replace that with

    "data": function ( d ) {
      d.mySearch = value;
    }
    

    Then your server script can access the mySearch value.

    Cheers,

    Colin

This discussion has been closed.