History | Log In     View a printable version of the current page.  
Issue Details (XML | Word | Printable)

Key: GRAILS-3002
Type: Improvement Improvement
Status: Open Open
Priority: Major Major
Assignee: Graeme Rocher
Reporter: Percy M. Wegmann
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
Grails

Enhance scaffolding to sort elements in drop-downs for many-to-one relationships in order to make it easier to find particular values

Created: 23/May/08 10:43 PM   Updated: 27/May/08 06:18 AM
Component/s: Scaffolding
Affects Version/s: 1.0.2
Fix Version/s: 1.1

Time Tracking:
Not Specified

Environment: All

Patch Submitted: Yes


 Description  « Hide
Right now, on the edit page generated by the default scaffolding, many-to-one relationships are rendered as html select drop-downs. The problem is that the items in these drop-downs are sorted in whatever order the GORM list() method returns them from the database. This order is neither stable nor user-friendly, making it hard to find a specific item from amongst a long list.

Since the select box already uses the toString() value of each object to populate the option text, I suggest also using toString() to sort the values. This way, they appear in a natural-looking order based on the information that is displayed. This simply requires calling sort { it?.tostring() } on the result of calling list(). This leads to the renderManyToOne() method in renderEditor.template looking as follows:

renderEditor.template
private renderManyToOne(domainClass,property) {
    if(property.association) {            
        return "<g:select optionKey=\"id\" from=\"\${${property.type.name}.list().sort{ it?.toString() }}\" name=\"${property.name}.id\" value=\"\${${domainClass.propertyName}?.${property.name}?.id}\" ${renderNoSelection(property)}></g:select>"
    }
}


 All   Comments   Work Log   Change History      Sort Order: Ascending order - Click to sort in descending order
There are no comments yet on this issue.