Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 841
Luixv Avatar asked Dec 18 '09 16:12

Luixv


1 Answers

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

like image 116
John Kinzie Avatar answered Nov 05 '22 13:11

John Kinzie