views:

29

answers:

1

Hi everyone,

I have a list of checkboxes like this:

<g:each in="${mylist}" var = "item" >
     <tr>
      <td colspan="2"><g:checkBox value="${dimension.id}" name="${item.id}"/> - ${item.name}</td>
     </tr>
</g:each>

I have to alter it so I get 2 columns in each row (2 checkboxes per row)

<g:each in="${mylist}" var = "item" >
   <td> checkbox with item </td>
   <td> checkbox with next item</td>
</g:each>

I wouldn't want to write a tag for this, and the scriptlet option does not look nice.

Is there any grailsy solution?

Thanks in advance

+1  A: 

How about using the status attribute:

<tr>
  <g:each status="i" in="${myList}" var="item">
    <g:if test="${ ( i > 0 ) && ( i % 2 == 0 ) }">
      </tr><tr>
    </g:if>
    <td><g:checkBox value="${dimension.id}" name="${item.id}"/> - ${item.name}</td>
  </g:each>
</tr>

Other than that, you're probably going to be writing your own grails tag.

You could do something like this to partiton your list into a list of pairs of data, then call each on that partitioned list.

All of this could be done in the GSP of course, it's just always neater wrapping these things in a tag and keeping out of the view.

tim_yates
+1 for the partitioning idea. Very useful.
Javid Jamae