Populating Table with an Object Array
Populating Table with an Object Array
MK01111000
Posts: 3Questions: 1Answers: 0
Hello all,
I'm trying to get my table populated with data from an object array.
Arrays are as follows:
COLUMNS
https://ibb.co/dEWpDH
What I've tried so far is:
$("#example").DataTable({
"data": data,
"columns": columns
});
I can't it to work. any ideas?
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
Take a look at this example, it has something very similar to your data structure. It'll show how to define those columns and data format.
Cheers,
Colin
Thanks Colin, that comes really close.
I guess the only difference is that each "row" of data in your example is captured in curly braces, while mine is not.
And to be honest I have no idea to circumvent this obstacle. any ideas?
The code that creates the object array from a google firebase database is as follows:
var data = [];
firebase.database().ref("DataSet-Schedule").once("value", function(snap){
snap.forEach(snapshot => {
Object.keys(snapshot.val()).map(k => {
data.push(Object.assign({}, {[k]:snapshot.val()[k]}))
})
})
})
console.log(data)
Yep, the data should be an array of objects, so you'll need to get those curly braces into your output format. I don't understand that code, I'm afraid, but it looks like it would need to go around the forEach block.
Thanks for your help Colin, I'll look for a solution.