Value of current element in objects

Value of current element in objects

stockmajstockmaj Posts: 2Questions: 0Answers: 0
edited February 2014 in DataTables 1.10
If I have data that looks like this
[code]
mydata:{
Adam:{
grade: 1,
gender: m
},
Betty:{
grade: 3,
gender: f
}
[/code]

and Columns "Name", "grade", "gender"
how do I access the name (Adam, Betty) as well as the data within. I can't use 0.grade, 1.grade, etc, I want the data for each element of my data, not for a specific element of mydata? The only way I've been able to make this work so far is by pre processing the objects into new objects that have all the data in a flattened structure.

I'd like to be able to do something like this:
[code]
data: mydata
columns: [ {data: ?}, {data: ?.grade}, {data: ?.gender} ]
[/code]

Replies

  • allanallan Posts: 61,972Questions: 1Answers: 10,160 Site admin
    Are you trying to have Adam and Betty as two different rows? That won't work in DataTables - it must be an array of data elements (be it objects, arrays, instances or whatever, but the outer container _must_ be an array).

    Allan
  • stockmajstockmaj Posts: 2Questions: 0Answers: 0
    Yes, 2 different rows.
This discussion has been closed.