Answer To Datatable Question
Answer to the following question: http://stackoverflow.com/questions/22474589/how-to-take-a-json-with-nested-jsons-to-an-html-table
HTML
<script src="https://raw.github.com/alfajango/jquery-dynatable/master/jquery.dynatable.js"></script>
<script src="http://underscorejs.org/underscore.js"></script>
<div id="tableDiv"></div>
JavaScript
function pintarTablaInutil(diferencias) {
$("#tableDiv").empty()
var th = "";
for (var i = 0; i < _.keys(_.first(diferencias)).length; i++) {
th += '<th>' + (i + 1) + '</th>'
}
var table = "<table id='resultados' class='table'><thead>" + th + '</thead><tbody></tbody></table>';
$("#tableDiv").append(table);
$('#resultados').dynatable({
features: {
paginate: false,
sort: false,
search: false,
perPageSelect: false,
recordCount: false
},
dataset: {
records: diferencias
}
});
}
var diferencias = {
"8": {
"1": 46.0,
"0": 45.0,
"2": 49.0
},
"2": {
"1 2": 3.0,
"0 1": 0.3333333333333333
},
"3": {
"0 1 2": 0.6666666666666666
}
};
var row = {};
_.map(_.keys(diferencias), function(val) {
row[val] = JSON.stringify(diferencias[val]);
console.log(val);
});
var dataset = [row];
pintarTablaInutil(dataset);