Datatable not show record from list javascript

Datatable not show record from list javascript

vantonio79vantonio79 Posts: 1Questions: 0Answers: 0
edited August 2023 in Free community support

Hello, I'am new to datatables and I want to load data from list json javascript.
I load data in list via this script javascript

function costruisciListaOrdini(result){
    let vet = null;
    try{
        vet = JSON.parse(result);
    }
   catch (e) {
      alert("sto qua 0 "+e.name+" "+e.message);
   }
   let lista=[];
   if(vet != null){
      let i=0;
      for (i=0;i<vet.length;i++){
        var obj={};
        obj.Codice=vet[i].codice;
        obj.Cliente=vet[i].cliente.nomeCliente+" "+vet[i].cliente.cognomeCliente;       
       lista.push(obj);
     }
  }
  return lista;
        
}

and after in other function javascript i create datatable with this code:

function recuperaOrdiniAttivi(){
    
    let json_dati='{"operazione":"5"}';
    $.ajax({
           url:'controller/ChiamateAjaxWeb.php',                
           data: json_dati,
           type: 'POST',
           contentType: "application/json",
           processData: false,
           async: false, //blocks window close
           success: function(result) {                            
                listaOrdini = null;
                listaOrdini=costruisciListaOrdini(result);      
                 var table = $('#tblElencoOrdiniAttivi').DataTable();
                 table.destroy();
                 table=null;
                $('#tblElencoOrdiniAttivi').DataTable({   
                        paging: true,
                        ordering: true,
                        info:     true,
                        responsive: true,
                        data: listaOrdini,  
                                columns: [
                                            { "data": "Codice" , render: function ( data, type, row ) { var html='<p>'+row.Codice+'</p>'; return html;}},
                                            { "data": "Cliente" , render: function ( data, type, row ) { var html='<p>'+row.Cliente+'</p>'; return html;}}
                                        
                                ],
                                columnDefs: [
                                       { targets: 0, width: '10%' },
                                       { targets: 1, width: '10%' }
                                      
                                ]                       
                  });
                alert("4");
                    
                 
            }  
    });
} 

Buw whent tables is created no record display in tables, when list json has 2 record.
why table not see record?
Thank you very much

Edited by Kevin: Syntax highlighting. Details on how to highlight code using markdown can be found in this guide

Replies

  • kthorngrenkthorngren Posts: 21,336Questions: 26Answers: 4,951
    edited August 2023

    There is nothing obvious in the code snippets. Do you get any alerts or errors in the browser's console?

    Can you post the value of listaOrdini after this statement?

    listaOrdini=costruisciListaOrdini(result); 
    

    Kevin

Sign In or Register to comment.