J.Srivastava
J.Srivastava

Reputation: 51

Show 2d data in a table using g:each grails

I am trying to display 2d data in a table the data is in the following way:

[[a,b],[c,d]]

and I want the display like this:

Date   |Journal
_________________
a.date |a.journal
b.date |b.journal
c.date |c.journal
d.date |d.journal

here a,b,c,d are object fetched from controller to GSP page. I want to use <g:each> to display data in the table. Please help..

Upvotes: 0

Views: 250

Answers (2)

J.Srivastava
J.Srivastava

Reputation: 51

<g:each var ="pb" in="${pBill}">
        <tr>
            <td>${pb[0].voucherDate}</td>
            <td>(PB)${pb[0].voucherNumber.voucherNumber}</td>

        </tr>
        <tr>
            <td>${pb[1].voucherDate}</td>
            <td>(PBR)${pb[1].voucherNumber.voucherNumber}</td>

    </g:each>

Upvotes: 0

dmahapatro
dmahapatro

Reputation: 50285

Either:

  • Flatten the original list to end up with one list to iterate over.

Example:

[[a,b],[c,d]].flatten() == [a, b, c, d]

and use one g:each.

OR

  • Iterate over the 2d array twice.

example:

<g:each var="elem" in="${mainList}">
    <g:each var="item" in="${elem}">
        <!-- Create the tabular structure -->
    </g:each>
</g:each>

Upvotes: 1

Related Questions