That part won’t be a problem if I knew how to loop through a multidimensional associative array as the one I provided.
[
{"B":"B2","C":"C2","D":"D2"},
{"B":"B3","C":"C3","E":"E3"},
{},
{"B":"B5","D":"D5","E":"E5","F":"F5"},
{"B":"B6","C":"C6","D":"D6","E":"E6"},
{"B":"B7","C":"C7","D":"D7"}
]
the following part let me store all keys into an array:
var keys = [];
for (var i = 0; i < data.length; i++) {
for (var categoryid in data[i]) {
var category = data[i][categoryid];
keys.push(categoryid);
}
}
result = Array [ "B", "C", "D", "G", "B", "C", "E", "B", "D", "E", … ]
after having done so I change all the keys (which are excel-based column letters) into numbers.
This enables me to calculate the numbers of columns needed in the to be created HTML-table.
var foo = function(val) {
var base = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', i, j, result = 0;
for (i = 0, j = val.length - 1; i < val.length; i += 1, j -= 1) {
result += Math.pow(base.length, j) * (base.indexOf(val[i]) + 1);
}
return result;
};
keysConverted = keys.map(foo);
result = Array [ 2, 3, 4, 7, 2, 3, 5, 2, 4, 5, … ]
After having done so I check the lowest and highest value and by deducting them from eachother I get the number of columns needed.
vMin = Math.min.apply(null, keysConverted); // result = 2
vMax = Math.max.apply(null, keysConverted); // result = 10
vMax - vMin // result = 8
data.length // result = 6 (number of rows)
Although I am not finished yet, I think there should be a way to loop through the associative array and create an table from it