How do I filter in Grails?

I am working on a Grails application. There is a domain class "member" - the view has the ability to select some filters. These filters are applied through the appropriate controller. Once the filter is applied to the selection, the result will be published.
Now the problem is that I don't know how to get these filters back or clear them. Obviously, a simple HTML reset button in the view will not work, since the filtered result is POST

ed.

Can anyone tell me how to clear the filters in use?
I don't want a hardcoded href

one that redirects the user to a regular "list".
Any idea (s)?

+2


source to share


1 answer


There are many ways to do what (I think) you want to do. One idea is to create another action in the same controller as the filter action that returns the list you want. I could try to give you an example, but from the code you posted it is not clear from which view you want, which view should be displayed after the filter is cleared, or from where the hardcoded id (1) comes from. Also, is it possible that the code you posted was modified in an attempt to fix this issue? The getParticipants method doesn't show up at all.

If you want to answer some of these questions: initial view, target view (after clearing filters), controller involved and where the id is coming from, I might try to give you a better answer.

Thanks for the additional information. Here's one possible solution. I haven't tried this, so the syntax might not be accurate, but it will get you started:

It looks like you will get no filters, these are all conference attendees. If this is correct, you can add such an action to ParcipantController.groovy



def clearFilter = {
    def conference = Conference.get(params.id)
    def participants = conference.participants
    render(view:'list', model:[participants: participants, 
     participantsTotal: participants.size(),
     startDate:conference.start, 
     endDate:conference.end,
     canWrite: accessRightsService.canWrite(request.beholder, conference)])
}

      

Then you can add the tag to your page instead of the hardcoded anchor tag like this: Clear filter

I hope this helps, Dave

+4


source







All Articles