Thanks Pascal, I was stuck at sortableColumn. I will try this out.
-----Original Message-----
From: Pascal Demilly [mailto:
list.grails@...]
Sent: Friday, August 15, 2008 10:58 AM
To:
user@...
Cc: Ramanathan, Kannan [CMB-IT]
Subject: Re: [grails-user] list.gsp with filter and pagination
Here is what I finally end up doing.
in list.gsp I added at the top:
<style type="text/css">
.filterBar {
margin-top:1px;
float:right;
vertical-align: middle;
}
</style>
and inserted this after <body>
<span class="filterBar"><g:form controller="item"
action="search">
<label>Filter:
<g:textField name="filter" value="${filter}"/>
<g:submitButton name="search" value="go"/>
<g:submitButton name="search" value="clear"/>
</label>
</g:form>
</span>
Then change the sortableColumn and paginate button as follow
<tr>
<g:sortableColumn property="id" title="Id" params="${params}"/>
<g:sortableColumn property="sku" title="Sku" params="${params}"/>
<g:sortableColumn property="description" title="Description"
params="${params}" />
</tr>
<div class="paginateButtons">
<g:paginate total="${Item.count()}" params="${params}"/> </div>
however there is a bug in sortableColumn. If you include params you need
to add at line 458 of
grails-1.0.3/src/groovy/org/codehaus/groovy/grails/plugins/web/taglib/Re
nderTagLib.groovy
linkParams.sort = property
because sort is already defined in params. If you don't overwrite it in
linkParams then all your column will have the same sort property.
I haven't found yet the way to make that change sticky. (modifying that
groovy file in place doesn't seem to be seen by the runtime) So in the
meantime I created a new taglib with that change and things are looking
great
I am now going to try to make it a template
Hope that helps
Pascal
On Friday 15 August 2008 04:57:29 am Ramanathan, Kannan wrote:
> Hi Pascal,
>
> I am exactly looking for such feature in my app. Can you please post
> sample code (especially how to remember the filter value when
> pagination is clicked)?
>
> Thanks for your help.
>
> -----Original Message-----
> From: Pascal Demilly [mailto:
list.grails@...]
> Sent: Friday, August 15, 2008 4:42 AM
> To:
user@...
> Subject: Re: [grails-user] list.gsp with filter and pagination
>
> (resent because of slippery fingers :-)
>
> Thanks Daniel. I had tried that with sortableColumn when I read the
> code in RenderTagLib that used attr.params like that:
>
> <g:sortableColumn property="description" title="Description"
> params="$params" />
>
> but got an error
>
> groovy.lang.MissingMethodException: No signature of method:
> java.util.LinkedHashMap.putAll() is applicable for argument types:
> (org.codehaus.groovy.runtime.GStringImpl) values:
> {["max":20, "action":"list", "controller":"item"]}
> at
> home_pdemilly_NetBeansProjects_grails_test_5_grails_app_views_item_lis
> t_
> gsp.run(home_pdemilly_NetBeansProjects_grails_test_5_grails_app_views_
> it
> em_list_gsp:47)
> list: ["max":20, "action":"list", "controller":"item"]
>
> How would you pass that attributes then? How do you specify a map in
> GSP?
>
> In the meantime I recreated my own paginate which put the filter value
> in the linkParams and that works. Now I am working on the sorting.
>
> Thanks
>
> Pascal
>
> On Friday 15 August 2008 12:55:03 am Daniel J. Lauk wrote:
> > Add the params attribute to the paginate tag.
> >
> > Cheers,
> > DJ
> >
> > Pascal Demilly wrote:
> > > Hi,
> > >
> > > I am trying to add a search filter (based on the definite guide to
> > > Grails) to one of my list.gsp.
> > >
> > > def search = {
> > > if (params?.search == 'clear') {
> > > params.filter = ''
> > > }
> > > redirect (view: list, params: params)
> > > }
> > >
> > > def list = {
> > > def items
> > >
> > > if(!params.max) params.max = 20
> > > if (params?.filter) {
> > > def criteria = Item.createCriteria()
> > > items = criteria.list(params) {
> > > or {
> > > ilike ('sku', "%${params.filter}%")
> > > ilike ('description',
"%${params.filter}%")
> > > ilike ('model', "%${params.filter}%")
> > > ilike ('primaryVendor',
>
> "%${params.filter}%")
>
> > > }
> > > }
> > > }
> > > else
> > > items = Item.list (params)
> > >
> > > render (view: 'list', model: [ itemList: items, filter:
> > > params.filter ], params: params)
> > > }
> > >
> > > The problem is that when the user press the pagination, the filter
> > > is lost. How can I access the view model from the controller or
> > > how can I make the pagination to remember the filter value
> > >
> > > TIA
> > >
> > > Pascal
> > >
> > > ------------------------------------------------------------------
> > > --
> > > - To unsubscribe from this list, please visit:
> > >
> > >
http://xircles.codehaus.org/manage_email>
> ---------------------------------------------------------------------
> To unsubscribe from this list, please visit:
>
>
http://xircles.codehaus.org/manage_email---------------------------------------------------------------------
To unsubscribe from this list, please visit:
http://xircles.codehaus.org/manage_email