I am looking to present some data in an interactive table on a web page, using the DataTables javascript library. The example I am interested in looks like this. This table is great because child rows showing extra(detailed) information can be shown and then hidden. The JSON data I am trying to display looks like this
{
"data": [
{
"student_name": "jack",
"subjects": {
"math": {
"cat1_grade": "30",
"cat2_grade": "39",
"cat3_grade": "38"
},
"english": {
"cat1_grade": "30",
"cat2_grade": "39",
"cat3_grade": "38"
},
"swahili": {
"cat1_grade": "30",
"cat2_grade": "39",
"cat3_grade": "38"
}
},
"subject1_average": "35",
"subject2_average": "26",
"subject3_average": "59"
}
]
}
I want my table to have columns for student name,subject1 average,subject2 average and subject3 average. When a row is expanded it should have under the student name their scores for each one of the cat(continuous assesment tests) for each subject area.
Currently I am not sure how to deal with the nested data. In the example the format(d) function displays more data, but the data is pretty straight forward.
/* Formatting function for row details - modify as you need */
function format ( d ) {
// `d` is the original data object for the row
return '<table cellpadding="5" cellspacing="0" border="0" style="padding-left:50px;">'+
'<tr>'+
'<td>Full name:</td>'+
'<td>'+d.name+'</td>'+
'</tr>'+
'<tr>'+
'<td>Extension number:</td>'+
'<td>'+d.extn+'</td>'+
'</tr>'+
'<tr>'+
'<td>Extra info:</td>'+
'<td>And any further details here (images etc)...</td>'+
'</tr>'+
'</table>';
}
My question is how do I get the javascript to decode each of the items in the subjects 'field' and display them in the table when expanded. I am not really familiar with javascript or JSON really. I am more familiar with Python on desktops. I am not even sure if this is the best library.
If there's something that works well with python, do share though I suspect that when it comes to displaying data on a web page, javascript is king