How to load JSON data to the datatable via LOOP??

How to load JSON data to the datatable via LOOP??

AbdullahCNAVBVAbdullahCNAVBV Posts: 3Questions: 1Answers: 0
edited August 2017 in Free community support

Hi Everyone I had difficulties in loading JSON data to each tuple of the datatable via LOOP..
Here is my code below...

var return_data = new Array();
                        for (var iii=0;iii<jsonData.length;iii++)
                        {
                            //jsonData=JSON.parse;
                            var timestamp = jsonData[iii]["time"];
                            var date = new Date(timestamp*1000 +(480*60000)); 
                            var date = new Date(timestamp*1000);
                            var iso = date.toISOString().match(/(\d{4}\-\d{2}\-\d{2})T(\d{2}:\d{2}:\d{2})/);
                            return_data.push({
                                    'time': iso[1] + ' ' + iso[2] + ' '+ timestamp,
                                    'sourceCountry'  : jsonData[i]["country.src"],
                                    'destCountry'   : jsonData[i]["country.dst"]
                                                
                                            })
                        }
                        var alltable = $('#attacks').DataTable({
                            "columns": [
                                        { "data": 'time' },
                                        { "data": 'sourceCountry' },
                                    { "data": 'destCountry' }
                                ],
                                "order" : [[0, "desc" ]]
                        });

Can you please help me ???????????

Answers

  • allanallan Posts: 63,471Questions: 1Answers: 10,467 Site admin

    I don't see where you are adding the data to the DataTable. If you have the data in Javascript, use rows.add(), or if you have it at initialisation time, use data

    Allan

This discussion has been closed.