How to show results in a list Grails gsp -
i have student class has relationship one-to-many note class
class student { string name static hasmany = [notes: note] } class note { double note int bimester static belongsto = [student:student] } when display result user in usernotes.gsp shown: use: <g:each var="n" in="${studentinstance.notes}">
discipline note bimester mathematics | 0 | 1 mathematics | 0 | 2 mathematics | 0 | 3 mathematics | 0 | 4 portuguese | 0 | 1 portuguese | 0 | 2 portuguese | 0 | 3 portuguese | 0 | 4 but wanted show following:
discipline | bimester 1 | bimester 2 | bimester 3 | bimester 4 mathematics 0 0 0 0 portuguese 0 0 0 0
you can group data in controller:
def usernotes() { def student = student.get(1) def disciplines = [:].withdefault { [0, 0, 0, 0] } (note note in student.notes.sort { it.bimester }) { disciplines[note.discipline].set(note.bimester - 1, note.note) } [disciplines: disciplines] } and display with
<table> <thead> <tr> <th>discipline</th> <th>bimester 1</th> <th>bimester 2</th> <th>bimester 3</th> <th>bimester 4</th> </tr> </thead> <tbody> <g:each in="${disciplines}" var="entry"> <tr> <td>${entry.key}</td> <g:each in="${entry.value}" var='bimester'> <td>${bimester}</td> </g:each> </tr> </g:each> </tbody> </table>
Comments
Post a Comment