Drawcallback receive parameter external

Drawcallback receive parameter external

fael_christofanofael_christofano Posts: 13Questions: 2Answers: 0

Hi,
I have one table and this table need to be redraw after one event in external input of DataTable, for exemple one input radio.
When the user checked one radio option, is called the drawcallback function.
My logica is use the ajax in drawcallback, but I readed(and tried), but that is not possible.
My doubt is: How to send by parameter the input radio value in drawcallback function and to make request in server side?

This question has an accepted answers - jump to answer

Answers

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

    Hi @fael_christofano ,

    It might be better to say what you're trying to do, because as you said, the drawCallback is unlikely to be right place.

    If the buttons affect the drawing of the table, or the data that you want from the server, the best bet would be to call ajax.reload() in the click event for the radio button. You could send the value of the radio button, or some other logic based on the selection, to the server in ajax.data. This would force a reload based on the selection.

    Hope that helps,

    Cheers,

    Colin

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

    Hi @fael_christofano ,

    As I said, you can use ajax.data for that. Set it in the main ajax declaration in the table initialisation.

    Cheers,

    Colin

  • fael_christofanofael_christofano Posts: 13Questions: 2Answers: 0

    I Edited my question, did you see?

  • fael_christofanofael_christofano Posts: 13Questions: 2Answers: 0
    edited October 2018
    $(document).ready( function () {
    var table = $('#tabelaVagas').DataTable({
           "processing": true,
             "serverSide": true,    
             "ajax": {
                     url: "carregar-vagas.php",
                     data: {$("input[name='rAtivo']:checked").val()},
                     type: "POST",
                     error: function (){
                         $('#post_list_processing').css('display','none');
                     }
    })
    });
    
    $("input[name='rAtivo']").on('click', function(){
            event.preventDefault();    
            table.reload();
    })
    
  • colincolin Posts: 15,236Questions: 1Answers: 2,598
    edited October 2018 Answer ✓

    If you look at the examples on the page ajax.data, you'll see they're setting a value that goes into the JSON, you're not doing that.

    Your line 7 should be something like:

    data: {
       checkValue = $("input[name='rAtivo']:checked").val()
    }
    

    You would then access checkValue on the server.

  • fael_christofanofael_christofano Posts: 13Questions: 2Answers: 0

    Perfect Colin, but I modified this code, stayed like this

    data: function ( d ) {
    d.rAtivo = $("input[name='rAtivo']:checked").val();
    },

This discussion has been closed.