I am trying to make a filter for my data so other people can see it, lets say I have a bunch of Events, like a calendar, and I want to see all that have a name or title with the word “Soccer”.
I’ve been trying to figure out how to do it but nothing works for me, I also tried to use filterPane plugin but did not work quite as well and I prefer to write something myself and maybe upload it to the Grails plugins webpage for future references,
Any help would be greatly appreciated.
If it’s in a domain class try:
of if you don’t want to worry about upper/lower case:
If your book titles are in a collection:
Update:
So now that we have a more complete description of your problem, let’s figure out a simplified way to solve it.
Today, you want to search by event title and its date so we’ll start there then look at how we might generalize this and make more complete solution down the road.
Our general flow is going to be something like:
First, let’s create a view for the search form, in grails-app/views/entry/ create a file called search.gsp with the following content:
Next, we’ll create the controller. In grails-app/controllers/ create a new controller EntryController.groovy. You can do this by executing the ‘grails create-controller Entry’ if you don’t already have the EntryController created.
Now, we’ll create two controller closures:
and
Finally, let’s create a searchResults.gsp in grails-app/views/entry
So, now putting it all together:
As a disclaimer, I’m writing this code on the fly in the stack overflow text editor, so I won’t be surprised if there are a couple syntax issues that I missed. Hopefully the explanation will be enough to get you on your way. Now let’s talk about taking this basic example and polishing it up to a more respectable solution.
I would recommend you try to do the following after you get the hang of this basic example:
If you’re struggling to get the above solution to work, try to simplify it even further. Eliminate the date search and just search by title. Replace all the criteria logic in the searchResults action with:
Start simple and improve and you’ll get the hang of it in no time.
Good Luck!