Luixv
Luixv

Reputation: 8710

Groovy: Sorting Columns in a view: list

I have a Groovy application. I am rendering the view list using the following statement:

render (view: 'list', model:[reportingInstanceList: reportingInstanceList, reportingInstanceTotal: i, params: params]) 

The list.gsp is as follows:

The view is rendered but the default sorting is not working.

<g:sortableColumn class="tabtitle" property="id" title="Id" titleKey="reporting.id" />
<g:sortableColumn class="tabtitle" property="company" title="Company" titleKey="reporting.company" />

Unfortunately the default sorting (by id, by company, etc) are not working. Any hint why?

Thanks a lot in advance.

Luis

Upvotes: 7

Views: 8038

Answers (2)

Jacob
Jacob

Reputation: 4031

You can add two hidden fields in your form, set them dynamically with Javascript and send them together with your form.

Upvotes: 0

John Kinzie
John Kinzie

Reputation: 361

If you are asking about the sorting/order links at the top of the columns on the list page, the links are hrefs back to the controller and method that was originally used to populate the list. Plus the URLs include parameters for sort and order. For instance:

/tracker/bug/searchCurrentUserProject?sort=name&order=asc

The controller method will then need to handle the sort and order values from the link:

params.sort = params.sort ?: "priority"

params.order = params.order ?: "asc"

And pass them to the database query:

def bugList = Bug.createCriteria().list( sort:params.sort, order:params.order, max:params.max, offset:params.offset) { eq "projectId", new Integer (params.projectId) }

Upvotes: 15

Related Questions