views:

24

answers:

1

I'm working on a very, very quick and dirty application using almost entirely scaffold to do it. This is only for internal use, and it's just to replace a spreadsheet, so while I know that I shouldn't rely on scaffolds for real production use, I still intend to use them where I can for efficiency (...just wanted to make sure we aren't taken off track by the inevitable question!).

What I am curious about is since scaffolds can do quick and dirty CRUD, and you can do dynamic finders for searches, is there a way to dynamically show the "list" action of the scaffold with a constraint (i.e. show all items in the list that were created by this "user")? That would be fine for me...

Alternatively, is there anything available in Grails to allow "grouped" tables. Essentially the "list" action from the scaffold, but grouped by a particular attribute (again, think of grouping all the items by the user that created them).

Any help would be appreciated - I've scoured Google and some books with no luck, but wanted to check with the StackOverflow community before I dismiss the notion and write it by hand. Thanks!

+1  A: 

We did the same in our Grails application and it's relatively easy:

  1. Create a new form in the list.gsp referring to the list action <g:form action="list" method="post">
  2. Inside that form, declare a table with the fields you want to search on:

<div class="buttons"> <span class="button"><g:submitButton name="list" class="search" value=" ${message(code: 'default.button.search.label', default: 'Search')}"/></span> </div>

  1. In the list action, build up the query (using findAll, findWhere, .. whatever takes your fancy) and return that to the page:

[wardInstanceList : Ward.findAll(whereClause, [max: params.max, offset: params.offset]) , wardInstanceTotal : (int) Ward.executeQuery("select count(*) " + whereClause).get(0)]

The whereClause looks something like: "from Ward where ward = 'something' and room = 'something else'"

Molske
we use the query based search because our project uses Composite Primary Keys trough hibernate annotations which isn't that supported in Grails yet =)
Molske