Reload info with AJAX passing new params

Reload info with AJAX passing new params

jmcabjmcab Posts: 1Questions: 1Answers: 0

Hello,
Im trying to do this:
I have a method which it executes at the begining with the DataTable creation, with its options and with an ajax request with some params calling to php script. It executes correctly and send me back the correct data to fill the table.
The problem is coming now. When I trigger a button I want to reload the table with the new data from de php script passing it the new params through AJAX, but it doesnt work. I have tried destroying the table, ajax.reload, retrieving the table , etc, any help ?? Please

This is the first method which works perfectly:

function load_actions_routine(){
  $('#option_action').attr('disabled',false);
  
  json_boxes = JSON.stringify(checked_boxes);
  param ={
    'id_rutina_accion':id_rutina_accion_prueba,
    'check_box_status':json_boxes,
    'id_cdt':id_cdt_user,
    'id_linea':id_linea_user,
    'id_area':id_area_user,
    'id_apt':id_apt_user
  };
  
action_table = $('#acciones_table').DataTable({
    
    
    "infoFiltered":false,
    "ordering":true,
    "paging":true,
    "ajax":{
      "url":"_php/HRP/load_actions.php",
      "data":param,
      "type":"POST"
    },
      
      "language":{
        "search":"Buscar",
        "lengthMenu":"Mostrar _MENU_ acciones",
        "paginate":{
          "next":"Siguiente",
          "previous":"Anterior"
        },
        "infoFiltered":"(Filtrado de un total de _MAX_ acciones)",
        "infoEmpty":"Mostrando 0 de 0 entradas",
        "info":"Mostrando _START_ de _END_ acciones"
      },
      
      "columns":[
        {"data":"id_accion"},
        {"data":"estado"},
        {"data":"letra_sqcdp"},
        {"data":"nombre_rutina"},
        {"data":"descripcion"},
        {"data":"responsable_nombre_1"},
        {"data":"solucion"},
        {"data":"fecha_creacion"},
        {"data":"fecha_prevista_solucion"},
        {"data":"fecha_replanificacion"},
        {"data":"fecha_solucion"},
        {"data":"fecha_validacion"},
        
        {"data":"id_rutina"},
        {"data":"subaccion"},
        {"data":"desviacion"},
        {"data":"num_replan"},
        {"data":"recurrente"},
        {"data":"nombre_autor"},
        {"data":"id_usuario_autor"},
        {"data":"nombre_validar"},
        {"data":"id_usuario_val"},
        {"data":"nombre_rutina"},
        {"data":"nombre_seguridad"},
        {"data":"fecha_escalado"},
        {"data":"fecha_proximo_escalado"},
        {"data":"fecha_limite_confirmacion"},
        {"data":"limite_definitivo"}
  
      ],
      
      "columnDefs":[
        
        {
          "targets":[13],
          "visible":false,
          "searchable":false
        },
        {
          "targets":[14],
          "visible":false,
          "searchable":false
        },
        {
          "targets":[15],
          "visible":false,
          "searchable":false
        },
        {
          "targets":[16],
          "visible":false,
          "searchable":false
        },
        {
          "targets":[17],
          "visible":false,
          "searchable":false
        },
        {
          "targets":[18],
          "visible":false,
          "searchable":false
        },
        {
          "targets":[19],
          "visible":false,
          "searchable":false
        },
        {
          "targets":[20],
          "visible":false,
          "searchable":false
        },
        {
          "targets":[21],
          "visible":false,
          "searchable":false
        },
        {
          "targets":[22],
          "visible":false,
          "searchable":false
        },
        {
          "targets":[23],
          "visible":false,
          "searchable":false
        },
        {
          "targets":[24],
          "visible":false,
          "searchable":false
        },
        {
          "targets":[25],
          "visible":false,
          "searchable":false
        },
        {
          "targets":[26],
          "visible":false,
          "searchable":false
        }
  
      ]
  
  });



}



And the code below fails me.

function load_DataTable(){
  $('#option_action').attr('disabled',false);
  
  json_boxes = JSON.stringify(checked_boxes);
  param ={
    'id_rutina_accion':id_rutina_accion_prueba,
    'check_box_status':json_boxes,
    'id_cdt':id_cdt_user,
    'id_linea':id_linea_user,
    'id_area':id_area_user,
    'id_apt':id_apt_user
  };

  
  if($.fn.DataTable.isDataTable('#acciones_table')){
    
    action_table.clear().draw();
    action_table.ajax.reload();
  }
}


Regards

Answers

  • colincolin Posts: 15,143Questions: 1Answers: 2,586

    Hi @jmcab ,

    I would add ajax.data as a function in your table initialisation, which adds the value of a variable to the payload sent to the server. This can be an empty string to begin with, which you then fill with your param object above for the ajax.reload(),

    Hope that does the trick,

    Cheers,

    Colin

This discussion has been closed.