I am trying to display my data in my View in this type of illustrated format. The items surrounded by the square brackets are the headers for the table.
[Lecture]
ECE 201 Section 1 .. ..
ECE 201 Section 2 .. ..
ECE 201 Section 3 .. ..
[Lab]
ECE 201 Section 10 .. ..
ECE 201 Section 11 .. ..
ECE 201 Section 12 .. ..
[Recitation]
ECE 201 Section 20 .. ..
ECE 201 Section 21 .. ..
ECE 201 Section 22 .. ..
My JSON, well, for one class, looks like the following
{
year: "2015",
term: "Summer",
subject_code: "ECE",
course_no: "201",
instr_type: "Lecture",
instr_method: "Face To Face",
section: "003",
crn: "42953",
course_title: "Digital Logic",
credits: "3.0",
day: "R",
time: "06:30 pm - 09:20 pm",
instructor: "Teacher Name",
campus: "University Building",
max_enroll: "18",
enroll: "18",
building: "PLACE",
room: null,
description: "Introduction to logic for computing",
pre_reqs: "",
co_reqs: ""
}
Essentially, I want to display the instr_type ONCE as a header of the table, and in the table, display the corresponding data. You can assume the data return is ordered by instr_type, so if you have multiple labs and lectures, it will be returned like this - lab, lab, lab, lecture, lecture, etc
I feel like what I want to do would be much easier to achieve if my data was in this format:
{
year: "2015",
term: "Summer",
subject_code: "ECE",
course_no: "201",
instr_type: "Lecture",
info: [
{
instr_method: "Face To Face",
section: "003",
crn: "42953",
course_title: "Digital Logic",
credits: "3.0",
day: "R",
time: "06:30 pm - 09:20 pm",
instructor: "Teacher Name",
campus: "University Building",
max_enroll: "18",
enroll: "18",
building: "PLACE",
room: null,
description: "Introduction to logic for computing",
pre_reqs: "",
co_reqs: ""
}, {
instr_method: "Face To Face",
section: "004",
crn: "42954",
..
}
]
}
My question is how could I format my data within either my Controller or View so that I could achieve this effect? Apologies for the silly question; I feel like the answer to this question is very simple and I am just overthinking it.