I have a gigantic json file and wanted to open it in a jquery datatable
I made a script that populates the .json file into a jquery datatable table, but the problem is that it is not populating the way you would like it to be: link Also, I'm giving copy / paste and storing in an array of objects and sending them popular in the table, that way it's not working.
This is the script:
var json = [{
"tempoNS" : 4251649,
"tempoMS" : 4,
"tamanhoArray" : 1999,
"nome" : "Bubble iterativo"
}, {
"tempoNS" : 3064749,
"tempoMS" : 3,
"tamanhoArray" : 1999,
"nome" : "Bubble recursivo"
}, {
"tempoNS" : 994920,
"tempoMS" : 0,
"tamanhoArray" : 1999,
"nome" : "Insertion iterativo"
}, {
"tempoNS" : 908287,
"tempoMS" : 0,
"tamanhoArray" : 1999,
"nome" : "Insertion recursivo"
}, {
"tempoNS" : 1500831,
"tempoMS" : 1,
"tamanhoArray" : 1999,
"nome" : "Selection iterativo"
}, {
"tempoNS" : 1461891,
"tempoMS" : 1,
"tamanhoArray" : 1999,
"nome" : "Selection recursivo"
}, {
"tempoNS" : 176888,
"tempoMS" : 0,
"tamanhoArray" : 1999,
"nome" : "Merge iterativo"
}, {
"tempoNS" : 187754,
"tempoMS" : 0,
"tamanhoArray" : 1999,
"nome" : "Merge recursivo"
}, {
"tempoNS" : 105348,
"tempoMS" : 0,
"tamanhoArray" : 1999,
"nome" : "Quick recursivo"
}, {
"tempoNS" : 160588,
"tempoMS" : 0,
"tamanhoArray" : 1999,
"nome" : "Heap recursivo"
}, {
"tempoNS" : 100217,
"tempoMS" : 0,
"tamanhoArray" : 1999,
"nome" : "CombSort Sem Otimização"
}
];
var tamanhoJson = json.length;
var results = "";
for (var i = 0; i < tamanhoJson; i++) {
results += "<tr>";
results += "<td>" + json[i].tamanhoArray + " Elementos</td>";
results += "<td>" + json[i].nome + " </td>";
results += "<td>" + json[i].tempoNS + " ns</td>";
results += "<td>" + json[i].tempoMS + " ms</td>";
results += "</tr>";
}
results += "<br />";
var div = document.getElementById("example");
console.log(results);
div.innerHTML = results;
If I do with data already populated in html, it works: link
This is the .json file that I would like to be able to populate the jquery datatable: link
I'm following this example: link
What is the best way to do it, via ajax? I do not know this procedure, could you tell me how I do it?