javascript - Dynamically creating a datatable in dc.js using a deeply nested json -
i want create datatable using dc.js. javascript code follows:
datatable.width(800).height(800) .dimension(collegedimension) .group(function(d) { return "list of selected students" }) .size(100) .columns([ function(d) { return d.student_name; }, function(d) { return d.student_grade; } ]) .sortby(function(d){ return d.order-details.order-id; }) // (optional) sort order, :default ascending .order(d3.ascending);
i have json file looks :
[{ "college_name":"abc", "college_students":[ { "student_name":"xyz1", "student_grade":"a" }, { "student_name":"xyz2", "student_grade":"b" } ]},{ "college_name":"abc1", "college_students":[ { "student_name":"xyz3", "student_grade":"a" }, { "student_name":"xyz4", "student_grade":"b" } ]},{ "college_name":"abc2", "college_students":[ { "student_name":"xyz5", "student_grade":"a" }, { "student_name":"xyz6", "student_grade":"b" } ]}]
i have requirement cannot change structure of json.
is possible parse data , create data table has following structure using datatable?
your life crossfilter lot easier if flatten out data, can pretty in pre-processing step without changing source data:
var dd = /* data */; var all_students = []; dd.foreach(function(college) { college.college_students.foreach(function(student) { all_students.push({college_name: college.college_name, student_name: student.student_name, student_grade: student.student_grade}); }); });
now use all_students
crossfilter , won't have struggle complicated accessors , on.
Comments
Post a Comment