Best way to render two dimensional table in grails -
i need table displayed , headings, have 2 lists:
list1 = [a, b, c, d, e, f, g]
and list2
list of maps
list2 = [ [from: a, to: a, val:20], [from: a, to: b, val:10], [from: a, to: c, val:30], [from: b, to: a, val:10], [from: b, to: b, val:40] ]
the result should be
from b c d e f g 20 10 30 - - - - b 10 40 - - - - - c - - - - - - - d - - - - - - - e - - - - - - - f - - - - - - - g - - - - - - -
how can that?
<table> <tr> <th>from</th> <th>to</th> <g:each in="${list1}" var="item"> <th>${item}</th> </g:each> </tr> <g:each in="${list1}" var="fromitem"> <tr> <td>${fromitem}</td> <td></td> <g:each in="${list1}" var="toitem"> <td> ${list2.find{it.from==fromitem && it.to==toitem}?.val?:"-"} </td> </g:each> </tr> </g:each> </table>
Comments
Post a Comment