Reputation: 3189
I am new with Grails. I like the idea of all views can be generated with ease, however now I am facing some issues when I want to customize the display style of date of birth column in f:table
(as I understood this comes from fields plugin). The value of the column shown as
2017-09-27 00:00:00 ICT
Some portion of the _table.gsp
<g:each in="${collection}" var="bean" status="i">
<tr class="${(i % 2) == 0 ? 'even' : 'odd'}">
<g:each in="${domainProperties}" var="p" status="j">
<g:if test="${j==0}">
<td><g:link method="GET" resource="${bean}"><f:display bean="${bean}" property="${p.name}" displayStyle="${displayStyle?:'table'}" theme="${theme}"/></g:link></td>
</g:if>
<g:elseif test="${p.name instanceof java.util.Date}">
<td>Some style here</td>
</g:elseif>
<g:else>
<td><f:display bean="${bean}" property="${p.name}" displayStyle="${displayStyle?:'table'}" theme="${theme}"/></td>
</g:else>
</g:each>
</tr>
</g:each>
Do I have to override the _table.gsp
of the plugin ? If yes how ? Or is there a better way ?
Upvotes: 2
Views: 804
Reputation: 3932
There are a number of ways to implement, see docs here
One way of doing it is to create a file named _displayWrapper.gsp
in a subdirectory named the same as the field your'e trying to customize so e.g. if your domain is called Person
& the date field is dob
you'd create the following:
/views/person/dob/_displayWrapper.gsp
Then in _displayWrapper.gsp you have access to a bunch of fields such as the entire bean or in this case you probably just want the value so something like the following:
<g:formatDate date="${value}" format="EEE d MMM yyy HH:mm:ss" />
This should render the date field in the format specified in the f:table
.
Upvotes: 4