Grails scaffolding is displaying fewer columns than the domain
-
28-04-2021 - |
Question
I have 6 columns in my domain class. But i only see 5 columns on the controller list when scaffold is set to true. My database is mySql. When executed table is created with correct number of columns My domain class
class RouteDesc {
String routenumber
String routeoperator
String routeinstructions
Date validfrom
Date validto
String weekendavailablity
static constraints = {
routenumber blank:false, unique:true, display:true
routeoperator blank:false, display:true
routeinstructions blank:true, display:true
validfrom display:true
validto display:true
weekendavailablity display:true
}
//static belongs to = RouteId
String toString () {
return routenumber
}
}
My Controller class
class RouteDescController {
static scaffold = true
}
Solution 2
One more addition to what Jarred Olson suggested
props.eachWithIndex { p, i ->
if (i < 6) {
...
}
}
Also change
<td><g:link action="show" id="\${${propertyName}.id}">\${fieldValue(bean: ${propertyName}, field: "${p.name}")}</g:link></td>
<% } else if (i < 6) {
if (p.type == Boolean.class || p.type == boolean.class) { %>
<td><g:formatBoolean boolean="\${${propertyName}.${p.name}}" />
</td>
OTHER TIPS
The default scaffolding list page limits the number of columns to 6 (since eachWithIndex is zero based) and 1 of them will be used for the ID column so only 5 attributes will show. If you'd like to change this you can install templates via grails install-templates
which (in Grails 2.0) will place the templates under src/templates/scaffolding/
. The template you'd need to update is the list.gsp about half way down there is the following code:
...
props.eachWithIndex { p, i ->
if (i < 6) {
...
}
}
You'd need to change that 6 to whatever you want it to be. As a side note the order that fields appear through scaffolding can be controlled by the order in which they are defined in the constraints ( http://grails.org/doc/latest/guide/scaffolding.html).