2

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
}
doelleri
  • 19,232
  • 5
  • 61
  • 65
Vicky Singh
  • 271
  • 1
  • 3
  • 7

2 Answers2

7

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).

Jarred Olson
  • 3,075
  • 1
  • 19
  • 34
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>
Vicky Singh
  • 271
  • 1
  • 3
  • 7
  • In Grails 2.4.3, the changes described above will go into src/templates/scaffolding/index.gsp. To ensure that both changes described above stay in sync, one could define a constant as follows and then, refer to this constant in the changes above. <% final MAX_COLUMN_INDEX = 10 %> – jkwuc89 Sep 05 '14 at 16:00